Django migrations not detecting all changes(Django 迁移未检测到所有更改)
问题描述
I have the following models.
BaseClass1
and BaseClass2
are abstract models used by models.
In this case, the model AdBreak
is used by a viewset and a serializer.
When I run python manage.py makemigrations
, the changes on AdBreak
model is detected. The model AdBreakStatus
is not getting created.
Since, AdBreakStatus
is linked to AdBreak
, I am expecting a migration for AdBreakStatus
also. Is my understanding wrong?
Edit
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.
Thanks in advance for the help.
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
I solved it in multiple ways.
Solution 1
There is a serializer AdBreakSerializer
which serializes the model AdBreak
.
Import AdBreakStatus
model into the AdBreakSerializer
file.
Now AdBreakStatus
model is detected and migrated.
Problem in this approach is that, the import is not used, and hence will not follow the standards.
Solution 2
Write the AdBreakStatus
model class inside the same file of AdBreak
. This will also solve the problem.
Finding / Understanding
The makemigrations
script looks for models which are connected from urls.py
. The script navigates from urls.py
to all the viewset, then the corresponding serializers and models.
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.
这篇关于Django 迁移未检测到所有更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Django 迁移未检测到所有更改


基础教程推荐
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01