When I make a change to my models (only to add a column during development!), Django won't issue any ALTER TABLE
statements to update the database. Is there a way to get this implemented or worked around? - other then adding the columns manually?
Note I'm not really looking for a full-migration solution, just something that lets me keep coding as I add columns on the way.
Use python manage.py sqlclear YOURAPP
in conjunction with dumpdata
and loaddata
(simplified version of answer by fish2000, which also uses a specific app):
DB=/path/to/db.sqlite3
APP=YOURAPPNAME
tmpdate=$(date "+%Y%m%d-%H%M%S")
echo "+ Dumping django project database to fixture DUMP-${tmpdate}.json ..." &&\
python manage.py dumpdata $APP --format='json' --indent=4 --verbosity=1 > datadumps/DUMP-${tmpdate}.json &&\
echo '+ Backing up sqlite binary store...' &&\
cp $DB $DB.bk &&\
echo '+ Rebuilding database structure from model defs...' &&\
python manage.py sqlclear $APP &&\
echo "+ Reloading project data from fixture dump DUMP-${tmpdate}.json ..." &&\
python manage.py loaddata datadumps/DUMP-${tmpdate}.json
Use a migration tool such as South.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With