我试图从Greku的数据库恢复到Greku的数据库.使用恢复的postgres数据库Django正常运行.它检索所有对象并使用它们的字段、主键等,没有任何问题.
但是,当涉及到写入数据库时,无论模型如何,我都会遇到同样的错误.
psycopg2.IntegrityError:"id"列中的null值违反了not null约束
当我重置heroku数据库并从空白板创建对象时,没有问题.但如果我试图在恢复的数据库上创建任何对象,我总是得到null value in column "id" violates not-null constraint
下面是试图在Django Admin中创建基本模型的复制/粘贴堆栈跟踪.我 Select 这个模型示例是因为没有与创建它相关的额外代码.没有信号什么的.
Django版本:2.0 Python版本:3.6.3
回溯:
文件
上述异常(列"id"中的null值与not null冲突)
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
文件
异常类型:IntegrityError at/admin/fantasy/raceclass/add/
The model from stack trace (keep in mind this error happens to every model, not just this [very basic] one.)
class RaceClass(models.Model):
title = models.CharField(max_length=140)
slug = models.SlugField(unique=True)
def __str__(self):
return self.title
class Meta:
ordering = ['title']
以下是我如何将(d)本地数据恢复到heroku:
我正在使用以下命令转储本地Postgres数据库(10.0版):
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
然后上传到AWS,并使用以下命令恢复到Heroku上的Postgres数据存储(9.6.5版):
heroku pg:backups:restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' DATABASE_URL
这两个都直接来自Heroku文档:https://devcenter.heroku.com/articles/heroku-postgres-import-export
旁注:我在本地使用10.0版Postgres,Heroku数据存储是9.6.5