如何使用 manage.py 加载 .sql 文件
How to load .sql file with manage.py
我有一个来自我的生产服务器的 .sql 文件,现在正试图将它加载到另一个生产服务器的数据库中。我试过 python manage.py 加载数据,但它给我一个错误
CommandError: Problem installing fixture 'social': sql is not a known serialization format.
如何将我的数据从 .sql 文件加载到带有 manage.py 的 postgres 中?
您不能使用 django 直接导入 sql 数据转储。为此,您应该使用 pg 的内部数据库导入工具。
根据 initial data
上的文档,Django 管理不适用于 SQL
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
如果您仍想使用 SQL 加载数据,您可以 data migration
你可以试试
cat filename.sql | python manage.py dbshell
我有一个来自我的生产服务器的 .sql 文件,现在正试图将它加载到另一个生产服务器的数据库中。我试过 python manage.py 加载数据,但它给我一个错误
CommandError: Problem installing fixture 'social': sql is not a known serialization format.
如何将我的数据从 .sql 文件加载到带有 manage.py 的 postgres 中?
您不能使用 django 直接导入 sql 数据转储。为此,您应该使用 pg 的内部数据库导入工具。
根据 initial data
上的文档,Django 管理不适用于 SQLA 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
如果您仍想使用 SQL 加载数据,您可以 data migration
你可以试试
cat filename.sql | python manage.py dbshell