有没有办法从Django迁移中排除应用程序的模型?我知道用managed = False
更改模型元选项是一个选项,但每次都要编辑很多模型。有没有办法指定我不想迁移其模型的应用程序?
答案 0 :(得分:2)
从apps migrations目录中删除__init__.py
文件应该有效。
答案 1 :(得分:1)
从您设置中的已安装应用中删除该应用。
答案 2 :(得分:0)
如果您将数据库路由器与
def allow_migrate(self, db, app_label, model_name=None, **hints):
return False
示例。
class FilemakerRouter:
"""
A router to control all database operations on models in the
filemaker application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read filemaker models go to filemaker.
"""
if model._meta.app_label == 'filemaker':
return 'filemaker'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write filemaker models go to filemaker.
"""
if model._meta.app_label == 'filemaker':
return 'filemaker'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the filemaker app is involved.
"""
if obj1._meta.app_label == 'filemaker' or \
obj2._meta.app_label == 'filemaker':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
return False