获取Null值会在注册用户或尝试迁移时发生完整性错误

时间:2018-01-31 20:11:58

标签: python django heroku rds

最近将数据库迁移到RDS。使用django 2.0 现在,当我尝试注册用户时,我得到了一个:

 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 migrate,我会收到以下回复:

(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).

1 个答案:

答案 0 :(得分:1)

django_migrations.id列应该是自动递增的。您需要手动修改此列。您可能会发现其他型号存在同样的问题。

您可能会发现创建新数据库更容易,运行manage.py migrate创建表,然后最终迁移数据。