Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I automatically let syncdb add a column (no full migration needed)

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.

like image 876
vdboor Avatar asked Oct 13 '10 13:10

vdboor


2 Answers

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
like image 94
Alex Flint Avatar answered Sep 28 '22 16:09

Alex Flint


Use a migration tool such as South.

like image 44
Ignacio Vazquez-Abrams Avatar answered Sep 28 '22 18:09

Ignacio Vazquez-Abrams