I have a question about Django's migration feature when there is an existing table.
当存在现有表时,我对Django的迁移功能有疑问。
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.
当我尝试执行“./manage.py migrate”以便它可以从models.py创建上面的5个表时,我收到一条错误消息,因为有一个现有的表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.
由于TB_TEAM_INF是另一个团队正在使用的表,因此我无法删除该表。由于项目的限制,我无法使用分离的数据库。在这种情况下,我打开迁移文件,如0001_initial.py,并在迁移过程中临时手动删除模型对象TB_TEAM_INF。
Is there a better way to ignore existing tables when "./manage.py migrate" rather than manually editing the migration file?
在“./manage.py migrate”而不是手动编辑迁移文件时,是否有更好的方法可以忽略现有表?
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.
我尝试使用./manage.py迁移--exclude = TB_TEAM_INF或--ignore = TB_TEAM_INF选项,但似乎不接受这些选项。我正在使用Django 1.7.2。
1 个解决方案
#1
9
Add the managed
option to your model definition:
将托管选项添加到模型定义:
class TB_TEAM_INF(models.Model):
...
class Meta:
managed = False
Excerpt from the documentation:
摘自文档:
If False, no database table creation or deletion operations will be performed for this model.
如果为False,则不会对此模型执行数据库表创建或删除操作。
#1
9
Add the managed
option to your model definition:
将托管选项添加到模型定义:
class TB_TEAM_INF(models.Model):
...
class Meta:
managed = False
Excerpt from the documentation:
摘自文档:
If False, no database table creation or deletion operations will be performed for this model.
如果为False,则不会对此模型执行数据库表创建或删除操作。