If you don't want to set up migrations -- you may be able to use a trick like this:
export JANGY_PROJECT='/Users/fish/Dropbox/ost2/ost2'
export BPYTHON_INIT_SCRIPT='${JANGY_PROJECT}/utils/django_shell_imports.py'
export PYTHONPATH="${JANGY_PROJECT}:${PYTHONPATH}"
alias jangy="python manage.py"
alias bp="cd $JANGY_PROJECT && bpython --interactive $BPYTHON_INIT_SCRIPT"
function jangyfresh () {
tmpdate=$(date "+%Y%m%d-%H%M%S") &&\
cd $JANGY_PROJECT &&\
echo "+ Dumping django project database to fixture DUMP-${tmpdate}.json ..." &&\
python manage.py dumpdata --format='json' --indent=4 --verbosity=1 > datadumps/DUMP-${tmpdate}.json &&\
echo '+ Backing up sqlite binary store and taking database offline...' &&\
mv sqlite/data.db sqlite/data.db.bk &&\
echo '+ Rebuilding database structure from model defs...' &&\
python manage.py syncdb &&\
echo '+ Graceful-restarting Apache...' &&\
sudo apachectl graceful &&\
echo '+ Enabling write access on new sqlite file...' &&\
chmod a+rw sqlite/data.db &&\
echo "+ Reloading project data from fixture dump DUMP-${tmpdate}.json ..." &&\
python manage.py loaddata datadumps/DUMP-${tmpdate}.json &&\
echo '+ Rebuilding project database structure...'
}
... which what that bash function does is:
- Dumps the database out to a fixture,
named with a date/time stamp
- Backs up and deletes
the binary database file (SQLite in this
case, which it's comparatively easy
to delete the file in question)
- Resyncs the the DB from models (regenerating the binary DB file)
- (optional) Fixes the db files' perms (which dropbox can screw with, in my case here)
- Repopulates the new DB from the last fixture
- (optional) restarts apache
I use this during development to back things up and start from scratch -- sometimes it works if you add a column, sometimes it'll complain about the newly defined model field not having a database column.
In these cases I run the command, edit the models.py file, delete the DB file and reload the last fixture.
Obviously, I don't do this on a production install, nor I would not recommend that.