简体   繁体   中英

Equivalent of sqlall in Django 1.9?

I'm working in Django 1.9, and I'm trying to get the SQL that would be used to create database tables from models.py.

It seems that in previous version of Django one could do:

python manage.py sqlall <app_name>

But that no longer seems to be the case. I just get Unknown command: 'sqlall' . Nothing in the docs seems to offer this.

How can I see how my models are turned into SQL?

It is deprecated in Django 1.9 :

The SQL management commands for apps without migrations, sql, sqlall, sqlclear, sqldropindexes, and sqlindexes, will be removed.

The closest command you can use is sqlmigrate :

Prints the SQL for the named migration. This requires an active database connection, which it will use to resolve constraint names; this means you must generate the SQL against a copy of the database you wish to later apply it on.

You can use the migration name 0001_initial for the creation script, for example:

python manage.py sqlmigrate myapp 0001_initial

I found that using sqlmigrate was a pretty rotten solution for me. I'm setting up logical replications, and so I need the SQL of the database, not the SQL of individual migrations.

The solution I found was to use pg_dump with the --schema-only option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM