Updating models

Due to my little confidence in Django and my terrible horror at the thought of seriously messing up my beautiful project, I will ask for advice / instructions here.

The database where my Django project is on top has been modified (several field types have changed) and my models are now out of sync. Oddly enough, my Django is still working (God knows how), but I still want to update the models. How do I make it correct . Thank you so much in advance.


Marked as an answer. My actual discovery was:

./manage.py inspectdb > <file>
//Hands you all the tables from the database. 
//Then you update the models accordingly.

      

SIMPLE! :)

+2


source to share


2 answers


Maybe a little late, but you can take a look at South , which is the migration system for Django.

A common practice for your situation would be to run manage.py reset appname

where appname

is the name of the application that contains the models that you modified. Obviously you will want to dump the data in the affected tables first (find out which tables will be affected by the startup manage.py sqlreset appname

).



Finally, it is entirely possible that your site is still running successfully because you have not restarted the web server (I am assuming you are talking about a production environment, the development server reloads most of the changes automatically).

+11


source


If you have already made changes to the live database, perhaps you can just change the models and restart the web server.

As long as the field names are the same between the database and the models, you shouldn't have a problem.



That being said is a better idea use a migration tool like south (as Dominic suggested)

+1


source







All Articles