AWS DMS迁移会导致出现主键错误

时间:2017-10-25 19:20:59

标签: django postgresql amazon-web-services aws-dms

我正在使用带有django的AWS RDS postgres数据库。我将数据库迁移到新的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)。

任何类型的帮助都将受到高度赞赏

0 个答案:

没有答案