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

标签 python django migration

我有以下型号。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/

相关文章:

python - 如何读取包含数组的文本文件并将其放入数组中? (Python)

Python无法识别请求 header 中的cookie

python - Django 查询给定位置的有序对象

azure - 我可以使用哪些工具将基础设施从 AWS 自动迁移到 Azure?

php - CodeIgniter - ci_sessions 迁移

mysql - 如何在 Rails 中测试或调试我的迁移脚本?

python - 将字典条目转换为变量

python - 属性错误 : module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

python - Django:只允许一个 bool 字段为真

python - 安装django项目,数据库问题