39👍
The problem is simply that you’re getting the content types defined twice – once when you do syncdb
, and once from the exported data you’re trying to import. Since you may well have other items in your database that depend on the original content type definitions, I would recommend keeping those.
So, after running syncdb
, do manage.py dbshell
and in your database do TRUNCATE django_content_type;
to remove all the newly-defined content types. Then you shouldn’t get any conflicts – on that part of the process, in any case.
2👍
There is a big discussion about it on the Django ticket 7052. The right way now is to use the --natural
parameter, example: ./manage.py dumpdata --natural --format=xml --indent=2 > fixture.xml
In order for --natural
to work with your models, they must implement natural_key
and get_by_natural_key
, as described on the Django documentation regarding natural keys.
Having said that, you might still need to edit the data before importing it with ./manage.py loaddata
. For instance, if your applications changed, syncdb
will populate the table django_content_type
and you might want to delete the respective entries from the xml-file before loading it.
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-Get list item dynamically in django templates
- [Django]-Django :How to integrate Django Rest framework in an existing application?
0👍
This worked for me. You probably want to ensure the server is stopped so no new data is lost. Dump it:
$ python manage.py dumpdata --exclude auth.permission --exclude contenttypes --natural > db.json
Make sure your models don’t have signals (e.g. post_save) or anything that creates models. If you do, comment it out momentarily.
Edit settings.py to point to the new database and set it up:
$ python manage.py syncdb
$ python manage.py migrate
Load the data:
./manage.py loaddata db.json
- [Django]-Why won't Django use IPython?
- [Django]-Django Footer and header on each page with {% extends }
- [Django]-Annotate a queryset with the average date difference? (django)
0👍
I used pgloader, just take a few seconds to migrate successfully:
$ pgloader project.load
project.load file with:
load database
from sqlite:////path/to/dev.db
into postgresql://user:pwd@localhost/db_name
with include drop, create tables, create indexes, reset sequences
set work_mem to '16MB', maintenance_work_mem to '512 MB';
- [Django]-With DEBUG=False, how can I log django exceptions to a log file
- [Django]-How to test Django's UpdateView?
- [Django]-Django: show the count of related objects in admin list_display