2

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?

4

1 回答 1

3

为了让 django 检测到更改,您需要使用名为south. 现在,由于您已经提交了运行的意思python manage.py syncdb,您需要删除表并重新开始。

这就是你的做法(在你删除你的表之后):

  1. 使用南安装pip install south
  2. 将南添加到已安装的应用程序中,并确保它位于您创建的所有其他应用程序之前
  3. 运行这个:python manage.py schemamigration --inital <your app name>
  4. 运行这个:python manage.py migrate <your app name>
  5. 运行这个:python manage.py syncdb<-最后一次你需要运行它:)

希望这有帮助。

于 2013-07-04T16:24:25.403 回答