How to load .sql file with manage.py

11.9k views Asked by At

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 ?

3

There are 3 answers

0
iklinac On BEST ANSWER

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 command

Fixtures 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

4
Leon Chew On

You can try

cat filename.sql | python manage.py dbshell
0
Jason On

You can't import straight sql data dump using django. You should use pg's internal db import tools for that.