问题
I have a .sql file from one of my production servers, and am now trying to load it into the database of another. I tried python manage.py loaddata, but its giving me an error
CommandError: Problem installing fixture 'social': sql is not a known serialization format.
How can I load my data into postgres from a .sql file with manage.py ?
回答1:
Django managment doesn't work with SQL as per documentation on initial data
A fixture is a collection of data that Django knows how to import into a database. The most straightforward way of creating a fixture if you’ve already got some data is to use the
manage.py dumpdata
commandFixtures can be written as JSON, XML or YAML (with PyYAML installed) documents.
Loading data is easy: just call
manage.py loaddata <fixturename>
, where is the name of the fixture file you’ve created
If you still want to load data with SQL you could make data migration
回答2:
You can try
cat filename.sql | python manage.py dbshell
回答3:
You can't import straight sql data dump using django. You should use pg's internal db import tools for that.
来源:https://stackoverflow.com/questions/48737478/how-to-load-sql-file-with-manage-py