我试图使用makemigrations命令在现有的应用程序中创建迁移,但它输出“未检测到更改”。

通常我使用startapp命令创建新的应用程序,但在创建这个应用程序时没有使用它。

调试后,我发现它没有创建迁移,因为迁移包/文件夹从应用程序中丢失。

如果文件夹不存在或者我遗漏了什么,如果它创建文件夹会更好吗?


当前回答

我忘记写正确的论点了

class LineInOffice(models.Model):   # here
    addressOfOffice = models.CharField("Корхоная жош",max_length= 200)   #and here
    ...

在models.py 然后就不那么烦人了

在应用程序“myApp”中未检测到任何变化

其他回答

django在执行makemigrations命令时没有检测到要迁移的内容有多种可能的原因。

migration folder You need a migrations package in your app. INSTALLED_APPS You need your app to be specified in the INSTALLED_APPS .dict Verbosity start by running makemigrations -v 3 for verbosity. This might shed some light on the problem. Full path In INSTALLED_APPS it is recommended to specify the full module app config path 'apply.apps.MyAppConfig' --settings you might want to make sure the correct settings file is set: manage.py makemigrations --settings mysite.settings specify app name explicitly put the app name in manage.py makemigrations myapp - that narrows down the migrations for the app alone and helps you isolate the problem. model meta check you have the right app_label in your model meta Debug django debug django core script. makemigrations command is pretty much straight forward. Here's how to do it in pycharm. change your script definition accordingly (ex: makemigrations --traceback myapp)

多个数据库:

当使用django的Db Router时,Router类(你的自定义Router类)需要实现allow_syncdb方法。

Makemigrations总是为模型更改创建迁移,但是如果 allow_migrate()返回False,

我的问题(以及解决方案)与上面描述的不同。

我没有使用models.py文件,而是创建了一个models目录,并在那里创建了my_model.py文件,我把我的模型放在那里。Django找不到我的模型,所以它写道没有迁移可以应用。

我的解决方案是:在my_app/models/__init__.py文件中,我添加了这一行: 导入MyModel

还有一个边缘情况和解决方案:

我添加了一个布尔字段,同时添加了一个@属性引用它,具有相同的名称(doh)。注释属性和迁移看到并添加新字段。重新命名财产,一切都很好。

这是一个评论,但可能应该是一个答案。

确保你的应用程序名称在settings.py INSTALLED_APPS中,否则无论你做什么,它都不会运行迁移。

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'blog',
]

然后运行:

./manage.py makemigrations blog

我读过很多关于这个问题的答案,通常都是简单地用其他方式进行移民。但对我来说,问题在于模型的Meta子类。

我有一个应用程序配置,说label = <应用程序名称>(在apps.py文件,旁边的models.py, views.py等)。如果你的元类没有与应用标签相同的标签(例如,因为你把一个太大的应用拆分成多个),就不会检测到任何变化(也不会有任何有用的错误消息)。所以在我的模型类中,我现在有:

class ModelClassName(models.Model):

    class Meta:
        app_label = '<app name>' # <-- this label was wrong before.

    field_name = models.FloatField()
    ...

运行Django 1.10。