在注册用户或尝试迁移时,获取空值会破坏完整性错误 [英] Getting Null Value vilates integrity error when registering user or trying to migrate
本文介绍了在注册用户或尝试迁移时,获取空值会破坏完整性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近将数据库迁移到RDS.使用Django 2.0 现在,当我尝试注册用户时,我得到一个:
Recently migrated database to RDS. Using django 2.0 Now when I try to register a user I get a:
ProgrammingError at /accounts/register/
relation "auth_user" does not exist
LINE 1: SELECT (1) AS "a" FROM "auth_user" WHERE "auth_user"."userna...
^
如果我尝试进行manage.py迁移,则会收到以下响应:
If I try to manage.py migrate I get the following response:
(boxtrucks-Dleh71wm) bash-3.2$ python manage.py migrate
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, saferdb, sessions
Running migrations:
Applying accounts.0002_auto_20180131_0135...Traceback (most recent call last):
File "/Users/Dev/.local/share/virtualenvs/boxtrucks-Dleh71wm/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, accounts, 0002_auto_20180131_0135, 2018-01-31 20:01:35.801905+00).
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/Dev/.local/share/virtualenvs/boxtrucks-Dleh71wm/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
return self.cursor.execute(sql, params)
File "/Users/Dev/.local/share/virtualenvs/boxtrucks-Dleh71wm/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/Dev/.local/share/virtualenvs/boxtrucks-Dleh71wm/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, accounts, 0002_auto_20180131_0135, 2018-01-31 20:01:35.801905+00).
推荐答案
django_migrations.id
列应该是自动递增的.您需要手动修改此列.您可能会在其他模型上发现相同的问题.
The django_migrations.id
column should be auto-incrementing. You'll need to modify this column manually. You may well find the same problem with other models.
您可能会发现创建新数据库,运行manage.py migrate
创建表,然后最终迁移数据更加容易.
You might find it easier to create a fresh database, run manage.py migrate
to create the tables, then finally migrate your data.
这篇关于在注册用户或尝试迁移时,获取空值会破坏完整性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文