7

I have a question about Django's migration feature when there is an existing table.

ContentData
ContentType
Faq
UserLog
TB_TEAM_INF

When I try to do "./manage.py migrate" so it can create the 5 tables above from models.py, I got an error message because there is an existing table, TB_TEAM_INF.

Since TB_TEAM_INF is a table being used by another team, I cannot remove the table. I cannot use a separated database either due to constraints of the project. In this case I open the migration file like 0001_initial.py and manually remove the model object, TB_TEAM_INF temporarily during migration.

Is there a better way to ignore existing tables when "./manage.py migrate" rather than manually editing the migration file?

I tried --exclude=TB_TEAM_INF or --ignore=TB_TEAM_INF option with ./manage.py migrate but it seems those options are not accepted. I am using Django 1.7.2.

4

1 回答 1

12

managed选项添加到模型定义中:

class TB_TEAM_INF(models.Model):
    ...
    class Meta:
        managed = False

文档摘录:

如果为 False,则不会对该模型执行任何数据库表创建或删除操作。

于 2015-03-06T03:15:09.357 回答