Getting Null Value vilates integrity error when registering user or trying to migrate

試著忘記壹切 提交于 2020-01-03 02:30:12

问题


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...
                               ^

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

回答1:


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.

You might find it easier to create a fresh database, run manage.py migrate to create the tables, then finally migrate your data.



来源:https://stackoverflow.com/questions/48550676/getting-null-value-vilates-integrity-error-when-registering-user-or-trying-to-mi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!