is there any way to dump all sqlmigrations automatically ?

203 views
Skip to first unread message

Victor Wang

unread,
Aug 22, 2017, 9:41:24 PM8/22/17
to Django users
use "sqlmigrate " is too ineffective  to get all sql script to setup new database . 

is there anyway to dump all "sqlmigrate" for all apps ?

Daniel Hepper

unread,
Aug 23, 2017, 10:20:37 AM8/23/17
to Django users
You can try this command:

 python manage.py showmigrations -p | sed -e 's/\[ ] \(.*\)\.\(.*\)/\1 \2/' |  xargs -L1 python manage.py sqlmigrate

Here is what it does:

1. "python manage.py showmigrations -p" shows all migrations in the order they will be applied as a list with checkboxes.
2. "sed -e 's/\[ ] \(.*\)\.\(.*\)/\1 \2/'" will remove the checkboxes and split the migrations into app and migration name
3. "xargs -L1 python manage.py sqlmigrate" will execute python manage.py sqlmigrate for each line

Alternatively, why not just call python manage.py migrate?
Reply all
Reply to author
Forward
0 new messages