./manage.py 迁移时忽略现有 table
Ignoring existing table when ./manage.py migrate
当存在 table 时,我对 Django 的迁移功能有疑问。
ContentData
ContentType
Faq
UserLog
TB_TEAM_INF
当我尝试执行“./manage.py 迁移”以便它可以从 models.py 创建上面的 5 个 table 时,我收到一条错误消息,因为存在一个现有的table, TB_TEAM_INF.
由于 TB_TEAM_INF 是 table 被另一个团队使用,我无法删除 table。由于项目的限制,我也不能使用单独的数据库。在这种情况下,我打开迁移文件 0001_initial.py 并手动删除模型对象,TB_TEAM_INF 在迁移过程中临时删除。
在“./manage.py 迁移”时,是否有更好的方法来忽略现有的 table,而不是手动编辑迁移文件?
我尝试了 --exclude=TB_TEAM_INF 或 --ignore=TB_TEAM_INF 选项与 ./manage.py migrate 但似乎这些选项不被接受。我正在使用 Django 1.7.2.
将 managed
选项添加到模型定义中:
class TB_TEAM_INF(models.Model):
...
class Meta:
managed = False
文档摘录:
If False, no database table creation or deletion operations will be performed for this model.
当存在 table 时,我对 Django 的迁移功能有疑问。
ContentData
ContentType
Faq
UserLog
TB_TEAM_INF
当我尝试执行“./manage.py 迁移”以便它可以从 models.py 创建上面的 5 个 table 时,我收到一条错误消息,因为存在一个现有的table, TB_TEAM_INF.
由于 TB_TEAM_INF 是 table 被另一个团队使用,我无法删除 table。由于项目的限制,我也不能使用单独的数据库。在这种情况下,我打开迁移文件 0001_initial.py 并手动删除模型对象,TB_TEAM_INF 在迁移过程中临时删除。
在“./manage.py 迁移”时,是否有更好的方法来忽略现有的 table,而不是手动编辑迁移文件?
我尝试了 --exclude=TB_TEAM_INF 或 --ignore=TB_TEAM_INF 选项与 ./manage.py migrate 但似乎这些选项不被接受。我正在使用 Django 1.7.2.
将 managed
选项添加到模型定义中:
class TB_TEAM_INF(models.Model):
...
class Meta:
managed = False
文档摘录:
If False, no database table creation or deletion operations will be performed for this model.