我收到以下錯誤時:IntegrityError使用Django的loaddata切換到Postgres的
IntegrityError: duplicate key value violates unique constraint "users_userprofile_pkey"
我從MySQL遷移到Postgres的,所以我用傾銷從MySQL數據庫中的數據:
python2.7 manage.py dumpdata --indent=4 --natural > dump.json
我得到的錯誤,當我試圖將dump.json加載到PostgreSQL數據庫:
python manage.py loaddata dump.json
我有以下的信號,我的用戶/型號:
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")
我有一個UserProfile依賴於用戶模型。我如何只轉儲用戶數據(這是用Django內置的)。另外,當兩個模型相互依賴時,順序應該是什麼? – egidra 2012-08-09 22:57:51
爲用戶你可以'./ manage.py dumpdata auth'之後,只需轉儲您的UserProfile。對於相互依賴的模型,您應該使用我提到的乏味方法。遷移數據庫並非易事。這裏是另一個可能會幫助你的問題http://stackoverflow.com/questions/4964615/how-can-i-easily-convert-a-django-app-from-mysql-to-postgresql – Hassek 2012-08-09 23:12:18