Hello,
I have recently updated my model, added a BooleanField to it however when I do python manage.py syncdb
, it doesn't add the new field to the database for the model. How can I fix this ?
views:
1639answers:
4
+1
A:
Havent used django in a while, but i seem to remember that syncdb does perform alter commands on db tables. you have to drop the table then run again and it will create again.
edit: sorry does NOT perform alter.
Aliixx
2009-10-22 08:08:24
Then it's not running `alter table` commands, it's running `create table` commands.
Dominic Rodger
2009-10-22 08:09:44
well I have data in the db so it would be great if I overcome this problem without dropping.
Hellnar
2009-10-22 08:09:46
I think you wanted to say, that syncdb doesNOT perform alter commands. You do not have to drop the table, you can manually add the new field to your sql too.
Zayatzz
2009-10-22 08:10:16
yes but the question was referencing the use of syncdb, so in this case you would have to drop the table to use syncdb or use the plugin mentioned below.
Aliixx
2009-10-22 08:28:17
+11
A:
Django doesn't support migrations out of the box. There is a pluggable app for Django that does exactly that though, and it works great. It's called South.
If you have difficulty setting it up edit your question and I'll gladly help you out (you might want to post a comment on my answer so I get notified).
Dominic Rodger
2009-10-22 08:09:17
A:
Django currently does not do this automatically. Your options are:
- Drop the table from the database, then recreate it in new form using syncdb.
- Print out SQL for the database using
python manage.py sql (appname)
, find the added line for the field and add it manually usingalter table
SQL command. (This will also allow you to choose values of the field for your current records.) - Use South (per Dominic's answer).
che
2009-10-22 08:11:31
A complete drop and reload for something that should be done in-place? That's terrible.
Glenn Maynard
2009-10-22 09:19:22
Its a simple management command, not a migration suite! Django has no way of predicting how your data has changed or how to preserve it so it insists that you do it yourself. If you don't like it, use a migration tool like South.
Soviut
2009-10-23 03:21:06