Question

I just tested it myself. I had Django models, and there have already been instances of the models in the database.

Then I added a dummy integer field to a model and ran manage.py syncdb. Checked the database, and nothing happened to the table. I don't see the extra field added in.

Is this the expected behavior? What's the proper way of modifying the model, and how will that alter the data that's already in the database?

Was it helpful?

Solution 2

Please use south for any kind of changes to get reflected to your database tables, here goes the link for using south Link for South documentation

OTHER TIPS

Django will not alter already existing tables, they even say so in the documentation. The reason for this is that django can not guarantee that there will be no information lost.

You have two options if you want to change existing tables. Either drop them and run syncdb again, but you will need to store your data somehow if you want to keep it. The other options is to use a migrations tool to do this for you. Django can show you the SQL for the new database schema and you can diff that to the current version of the database to create the update script.

You could even update your database mannually if it is a small change and you don't want to bother with migrations tools, though I would recommend to use one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top