我正在将 AWS RDS postgres 数据库与 django 一起使用。我将数据库迁移到一个新的 RDS postgres 实例。我可以通过 django 连接到它并查看所有记录。但是每当我尝试添加记录时,让我们说新用户它给了我
django.db.utils.IntegrityError: null value in column "id" violates not-null constraint
有时我也得到
Primary key (id) duplication error.
我不明白,django 应该默认处理主键(id)和自动增量。奇怪的是为什么它在创建新记录时传递 null 或者为什么传递那些已经在使用的键。
当我尝试在以下位置添加带有发布请求的新用户时,这是完整的错误回溯http://localhost:8004/auth/registration/
Error Traceback:
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
The above exception (null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, pbkdf2_sha256$24000$1cswEvhYDOKU$HHvyyKyGO66j52iXtj3AD7ugos0s7so..., null, f, first_name, First_name, Last_Name, temp@example.com, f, t, 2017-10-26 09:13:30.790302+00).
) was the direct cause of the following exception:
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python3.5/contextlib.py" in inner
30. return func(*args, **kwds)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
466. response = self.handle_exception(exc)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
463. response = handler(request, *args, **kwargs)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/rest_framework/generics.py" in post
192. return self.create(request, *args, **kwargs)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/rest_auth/registration/views.py" in create
38. user = self.perform_create(serializer)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/rest_auth/registration/views.py" in perform_create
44. user = serializer.save(self.request)
File "/home/user/savemyscope/save-my-scope-django/savemyscope/users/serializers.py" in save
132. adapter.save_user(request, user, self)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/allauth/account/adapter.py" in save_user
214. user.save()
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/contrib/auth/base_user.py" in save
74. super(AbstractBaseUser, self).save(*args, **kwargs)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/base.py" in save
700. force_update=force_update, update_fields=update_fields)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/base.py" in save_base
728. updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/base.py" in _save_table
812. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/base.py" in _do_insert
851. using=using, raw=raw)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
122. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/query.py" in _insert
1039. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
1060. cursor.execute(sql, params)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/debug_toolbar/panels/sql/tracking.py" in execute
159. return self._record(self.cursor.execute, sql, params)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/debug_toolbar/panels/sql/tracking.py" in _record
101. return method(sql, params)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/utils.py" in __exit__
95. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/utils/six.py" in reraise
685. raise value.with_traceback(tb)
File "/home/user/.virtualenvs/save-my-scope-django/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
Exception Type: IntegrityError at /auth/registration/
Exception Value: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, pbkdf2_sha256$24000$1cswEvhYDOKU$HHvyyKyGO66j52iXtj3AD7ugos0s7so..., null, f, first_name, First_name, Last_Name, temp@example.com, f, t, 2017-10-26 09:13:30.790302+00)
我无法弄清楚整个过程中出了什么问题。这是从 postgres 到 postgres 的简单同质 DMS 迁移。迁移任务成功完成。它显示没有错误。所有具有公共模式的数据和表都已成功复制。但我无法向其中添加新记录。
注意:我尝试使用“pg_dump”命令迁移数据库,它工作正常。迁移后我能够向其中添加记录。我还尝试在两个实例上使用相同的 postgres 引擎版本(9.5)。
任何类型的帮助将不胜感激