我有以下型号。BaseClass1
和 BaseClass2
是模型使用的抽象模型。
在这种情况下,模型 AdBreak
由 View 集和序列化程序使用。
当我跑 python manage.py makemigrations
,AdBreak
上的变化检测到模型。型号AdBreakStatus
没有被创建。
因为,AdBreakStatus
链接到 AdBreak
,我期待迁移 AdBreakStatus
还。我的理解有误吗?
编辑
In the initial state, there was only AdBreak and BaseClass1 model. The new state, AdBreakStatus and BaseClass2 models were added. Some of the fields from AdBreak were moved to AdBreakStatus.
在此先感谢您的帮助。
class BaseClass1(models.Model):
class Meta:
abstract=True
timestamp = models.DateTimeField(auto_now_add=True)
class BaseClass2(models.Model):
class Meta:
abstract=True
other_field = models.IntegerField()
class AdBreak(BaseClass1):
class Meta:
db_table = "ad_break"
ad_break_id = models.AutoField(primary_key=True)
... # Other fields
class AdBreakStatus(BaseClass2):
class Meta:
db_table = "ad_break_status"
ad_break = models.ForeignKey(AdBreak)
... # Other Fields
最佳答案
我通过多种方式解决了它。
解决方案1
有一个序列化程序 AdBreakSerializer
序列化模型 AdBreak
.
进口 AdBreakStatus
模型进AdBreakSerializer
文件。
现在 AdBreakStatus
模型被检测和迁移。
Problem in this approach is that, the import is not used, and hence will not follow the standards.
解决方案2
写下
AdBreakStatus
AdBreak
同一文件中的模型类.这也将解决问题。发现/理解
makemigrations
脚本查找从 urls.py
连接的模型.脚本从 urls.py
导航到所有 View 集,然后是相应的序列化程序和模型。All the models which needs to be migrated should come in the path of this traversal. OR Only those models which are traversed in this manner will be migrated.
关于python - Django 迁移未检测到所有更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43093651/