TJB
TJB

Reputation: 3846

How to load .sql file with manage.py

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 ?

Upvotes: 5

Views: 13273

Answers (3)

Leon Chew
Leon Chew

Reputation: 261

You can try

cat filename.sql | python manage.py dbshell

Upvotes: 26

iklinac
iklinac

Reputation: 15738

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

Upvotes: 4

Jason
Jason

Reputation: 11363

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

Upvotes: 0

Related Questions