ResetDB
Revision as of 20:32, 23 September 2010 by Migratebot (talk | contribs) (Created page with "= Resetting your Django database ==
Often if you change a model, you will get a DatabaseError (or something like it) because your models are out of sync with your database fil...")
Resetting your Django database =
Often if you change a model, you will get a DatabaseError (or something like it) because your models are out of sync with your database file.
1. Delete the old database (NB: the data in this database will be lost!)
rm db/whatever.db
2. Use syncdb to rebuild...
python manage.py syncdb
Trying to preserve data
Use sqlite3 to manually manipulate the database
sudo apt-get install sqlite3
Run sqlite3 on your database file...
sqlite3 db/YOURDATABASE.db
Show a list of all the tables in the database
sqlite> .schema
Use the drop command to delete a particular table (the one you want to rebuild):
drop table music_text;
Use dump/load data
It is sometimes possible to use Django's dump and load data commands to keep your data when you make changes to the model. Note, however, that the loaddata command is very sensitive.
python manage.py dumpdata db/mydata.json
Now change your models and rebuild as per instructions above.
python manage.py loaddata db/mydata.json