我目前使用sqlite3作爲我的Django項目之一的數據庫。我想改變這個使用postgresql,我想保持所有的數據完好無損。加載datadump時將Django項目從sqlite3後端切換到postgresql失敗
我用./manage.py dumpdata > dump.json
創建數據轉儲,並將我的設置更改爲使用postgresql。試着先用空數據庫做./manage.py loaddata dump.json
導致表格不存在的錯誤,所以我跑./manage.py syncdb
,並再次嘗試。導致此錯誤:
Problem installing fixture 'dump.json': Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/django/core/management/commands/loaddata.py", line 163, in handle
obj.save()
File "/usr/lib/python2.6/site-packages/django/core/serializers/base.py", line 163, in save
models.Model.save_base(self.object, raw=True)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 495, in save_base
rows = manager.filter(pk=pk_val)._update(values)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 448, in _update
return query.execute_sql(None)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/subqueries.py", line 124, in execute_sql
cursor = super(UpdateQuery, self).execute_sql(result_type)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 2347, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 19, in execute
return self.cursor.execute(sql, params)
IntegrityError: duplicate key value violates unique constraint "django_content_type_app_label_key"
- 這不是從一個數據庫將數據移動到另一個正確的方法是什麼?
- 爲了安全地切換DB後端,我該怎麼做?
我忽略了一些Django的表。 './manage.py dumpdata -e sessions -e admin -e contenttypes -e auth.Permission -e authtoken --natural> db.json'然後執行'./manage.py loaddata db.json'。也許它有助於某人。有關詳細信息,請參閱此問題http://stackoverflow.com/questions/853796/problems-with-contenttypes-when-loading-a-fixture-in-django – 2015-04-21 17:42:59