Rhubarb
Rhubarb

Reputation: 4003

Changing models in django results in broken database?

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

Upvotes: 3

Views: 3441

Answers (3)

user306553
user306553

Reputation:

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...

Upvotes: 4

Esteban Küber
Esteban Küber

Reputation: 36832

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

Upvotes: 2

Barthelemy
Barthelemy

Reputation: 8757

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.

Upvotes: 9

Related Questions