Chris Pratt: A Django Snippet to Refresh Your Database
Slava
· 1 year ago
Slight correction to first comment (from Keats) - there's a typo - it should be "loaddata" (double d).
Keats
· 1 year ago
you could have done it with a shell script like this : #!/bin/sh ./manage.py dumpdata >> blabla.json ./manage.py flush ./manage.py loadata blabla.json
or simply by adding a setting FIXTURE_DIRS = ( '/home/keats/fixtures', )
then ./manage.py dumpdata >> /home/keats/fixtures/initial_data.json
now each time you call : ./manage.py flush it will flush the database and automatically reload the data in the initial_data.json the name of the file is important
you can also add sql directory in application directory the syntax is sql/model_name.json or .sql and it will be loaded each time you flush your database
++
Chris Pratt
· 1 year ago
Well, I feel a little stupid ;). But that's why I posted this. Thanks for the tips.
like this :
#!/bin/sh
./manage.py dumpdata >> blabla.json
./manage.py flush
./manage.py loadata blabla.json
or simply by adding a setting
FIXTURE_DIRS = (
'/home/keats/fixtures',
)
then ./manage.py dumpdata >> /home/keats/fixtures/initial_data.json
now each time you call :
./manage.py flush
it will flush the database and automatically reload the data in the initial_data.json
the name of the file is important
you can also add sql directory in application directory
the syntax is sql/model_name.json or .sql
and it will be loaded each time you flush your database
++