1. <i id='dILBc'><tr id='dILBc'><dt id='dILBc'><q id='dILBc'><span id='dILBc'><b id='dILBc'><form id='dILBc'><ins id='dILBc'></ins><ul id='dILBc'></ul><sub id='dILBc'></sub></form><legend id='dILBc'></legend><bdo id='dILBc'><pre id='dILBc'><center id='dILBc'></center></pre></bdo></b><th id='dILBc'></th></span></q></dt></tr></i><div id='dILBc'><tfoot id='dILBc'></tfoot><dl id='dILBc'><fieldset id='dILBc'></fieldset></dl></div>

    <small id='dILBc'></small><noframes id='dILBc'>

    <legend id='dILBc'><style id='dILBc'><dir id='dILBc'><q id='dILBc'></q></dir></style></legend>

      <tfoot id='dILBc'></tfoot>
        <bdo id='dILBc'></bdo><ul id='dILBc'></ul>

      Django 迁移未检测到所有更改

      时间:2023-10-20

      <small id='zlgOp'></small><noframes id='zlgOp'>

      <legend id='zlgOp'><style id='zlgOp'><dir id='zlgOp'><q id='zlgOp'></q></dir></style></legend>

          <bdo id='zlgOp'></bdo><ul id='zlgOp'></ul>

              <tbody id='zlgOp'></tbody>
            <tfoot id='zlgOp'></tfoot>
              • <i id='zlgOp'><tr id='zlgOp'><dt id='zlgOp'><q id='zlgOp'><span id='zlgOp'><b id='zlgOp'><form id='zlgOp'><ins id='zlgOp'></ins><ul id='zlgOp'></ul><sub id='zlgOp'></sub></form><legend id='zlgOp'></legend><bdo id='zlgOp'><pre id='zlgOp'><center id='zlgOp'></center></pre></bdo></b><th id='zlgOp'></th></span></q></dt></tr></i><div id='zlgOp'><tfoot id='zlgOp'></tfoot><dl id='zlgOp'><fieldset id='zlgOp'></fieldset></dl></div>
                本文介绍了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 中的给定模型生成 CREATE TABLE SQL 语句? 下一篇:使用 imaplib 获取电子邮件,但不要将其标记为 SEEN

                相关文章

                <tfoot id='JrGLH'></tfoot>

                <small id='JrGLH'></small><noframes id='JrGLH'>

                • <bdo id='JrGLH'></bdo><ul id='JrGLH'></ul>
                <i id='JrGLH'><tr id='JrGLH'><dt id='JrGLH'><q id='JrGLH'><span id='JrGLH'><b id='JrGLH'><form id='JrGLH'><ins id='JrGLH'></ins><ul id='JrGLH'></ul><sub id='JrGLH'></sub></form><legend id='JrGLH'></legend><bdo id='JrGLH'><pre id='JrGLH'><center id='JrGLH'></center></pre></bdo></b><th id='JrGLH'></th></span></q></dt></tr></i><div id='JrGLH'><tfoot id='JrGLH'></tfoot><dl id='JrGLH'><fieldset id='JrGLH'></fieldset></dl></div>

                <legend id='JrGLH'><style id='JrGLH'><dir id='JrGLH'><q id='JrGLH'></q></dir></style></legend>