切换到 Postgres 时使用 Django 的 loaddata 的 IntegrityError

egi*_*dra 1 python mysql django postgresql

我收到以下错误:

IntegrityError: duplicate key value violates unique constraint "users_userprofile_pkey"
Run Code Online (Sandbox Code Playgroud)

我正在从 MySQL 迁移到 Postgres,因此我正在使用以下方法转储 MySQL 数据库中的数据:

python2.7 manage.py dumpdata --indent=4 --natural > dump.json
Run Code Online (Sandbox Code Playgroud)

当我尝试将 dump.json 加载到 Postgresql 数据库时出现错误:

 python manage.py loaddata dump.json
Run Code Online (Sandbox Code Playgroud)

我的用户/模型中有以下信号:

post_save.connect(create_user_profile, sender=User, dispatch_uid="user_create_profile")
post_save.connect(create_api_key, sender=User, dispatch_uid="user_create_api_key")
Run Code Online (Sandbox Code Playgroud)

egi*_*dra 5

我不得不注释掉 post_save 信号,然后执行 loaddata。