views:

139

answers:

3

I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't show up in the model:

Caught an exception while rendering: no such column: mySite_book.Title
+5  A: 

Django does not perform database migration for you, i.e., if you add new fields, Django won't modify your database schema.

You can either:

  1. Drop the tables that changed and perform syncdb again. This is reasonnable when you are developing your application and you don't have any real data in your database.
  2. Use a migration tool like South that performs database migration (like hibernate update script).
  3. Edit the database by hand and add/delete the appropriate fields for the previously existing tables.
Barthelemy
I'm using SQLite, how do I drop the tables? Can it be done from django? Or do I need to connect through the SQLite command console? And if I drop the tables, will the syncdb automatically rebuild them when I run it again?
Rhubarb
Yes, if you drop the table, syncdb will automatically rebuild them. You can use SQLite command console or one of the numerous gui tools such as: http://sourceforge.net/projects/sqlitebrowser/ and http://sites.google.com/site/sqlitetool/
Barthelemy
+1  A: 

Just to expand on @Barthelemy's answer, there are several Django migration tools:

voyager
+3  A: 

For me, (so long as you're doing this with test data, and not doing this in a production environ) it's alot easier to just blow away the test.db and do a new ./manage.py syncdb. Just food for thought...

baddriverdave