How to load .sql file with manage.py

与世无争的帅哥 提交于 2019-12-13 16:16:52

问题


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 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




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!