Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Models

Tags:

django

models

Due to my little confidence with Django and my sheer horror at the thought of seriously messing up my beautiful project, I shall ask for proper advice/instructions here.

The database that my Django project is sitting on top of has been changed (a few field types have been changed) and my models are now out-of-sync. Funnily enough, my Django still works (God knows how) but I still want to update the models. How do I go about doing this the proper way. Thank you very much indeed in advance.


Marked as answered. My actual discover was:

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

SIMPLE! :)

like image 866
Federer Avatar asked May 24 '26 15:05

Federer


1 Answers

It's probably a bit late, but you might want to take a look at South, which is a migrations system for Django.

The normal practice for your situation would be to run manage.py reset appname, where appname is the name of the app which contains the models you've changed. You'll obviously want to dump the data in the affected tables first (find out what tables are going to be affected by running manage.py sqlreset appname).

Finally, it's quite possible your site is still running happily because you've not restarted the webserver (I'm assuming you're talking about a production environment, the development server reloads most changes automatically).

like image 174
Dominic Rodger Avatar answered May 27 '26 20:05

Dominic Rodger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!