Question

I keep modifying my model in Django. However after I do it I have to go into the database, delete the table manually and then manage.py syncdb. I tried manage.py reset <<app_name>> but it doesn't drop then reinstall the model with the new fields. What is the proper way to do this or is the best way to go into the database, delete, then syncdb?

Was it helpful?

Solution

The behaviour you describe is explicitly mentioned in the docs:

syncdb will only create tables for models which have not yet been installed. It will never issue ALTER TABLE statements to match changes made to a model class after installation. Changes to model classes and database schemas often involve some form of ambiguity and, in those cases, Django would have to guess at the correct changes to make. There is a risk that critical data would be lost in the process.

What you are after is a tool for database migrations and that is a large problem mostly solved ;-)

So yes, as Marcin said, your are looking for South. Alternatively you could try Nashvegas and for small changes even sql_diff which is part of django-extensions is a viable option.

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