Jason
Jason

Reputation: 11363

Django model-database changes

I have a legacy database that I'm using in an app in Django. I used the django admin functionality to generate the models.py file from the existing tables.

If I make changes to the models, such as adding a unique_together constraint to models, are the changes managed by Django, or do I have to somehow apply said model changes to the database?

Upvotes: 2

Views: 435

Answers (1)

Nafiul Islam
Nafiul Islam

Reputation: 82450

In order for django to detect changes, you will need to use a third party migration tool called south. Now, since you've already committed meaning you ran python manage.py syncdb, you will need to delete the table and start over.

This is how you do it (after you have deleted your table):

  1. Install south using pip install south
  2. Add south to installed apps, and make sure it comes before all the other apps that you created
  3. Run this: python manage.py schemamigration --inital <your app name>
  4. Run this: python manage.py migrate <your app name>
  5. Run this: python manage.py syncdb <- last time you will need to run it :)

Hope this helped.

Upvotes: 3

Related Questions