gpt4 book ai didi

python - Django 迁移未检测到所有更改

转载 作者:行者123 更新时间:2023-12-03 16:41:52 24 4
gpt4 key购买 nike

我有以下型号。BaseClass1BaseClass2是模型使用的抽象模型。

在这种情况下,模型 AdBreak由 View 集和序列化程序使用。
当我跑 python manage.py makemigrationsAdBreak上的变化检测到模型。型号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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com