【问题标题】:Django 1.7 - makemigrations not detecting changes - managed modelsDjango 1.7 - makemigrations 未检测到更改 - 托管模型
【发布时间】:2014-09-11 15:34:22
【问题描述】:

我刚刚在我的虚拟环境中安装了 django 1.7。

然后我手动创建了以下文件:

service_bus/
service_bus/__init__.py
service_bus/django_settings.py
service_bus/models
service_bus/models/__init__.py
service_bus/models/dsp.py
service_bus/models/audience_type.py
service_bus/models/category.py
service_bus/models/audience.py
service_bus/models/dsp_config.py
service_bus/models/apsettings.py

所以我有一个设置文件service_bus/django_settings.pyservice_bus 应用程序。

然后我在 bash 上做了:

export DJANGO_SETTINGS_MODULE='service_bus.django_settings'

然后我只是尝试运行 makemigrations,但它说没有检测到任何更改。

$ django-admin makemigrations
Loading properties from /etc/s1mbi0se/dmp.ini
System check identified some issues:

WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
No changes detected


$ django-admin makemigrations service_bus
Loading properties from /etc/s1mbi0se/dmp.ini
System check identified some issues:

WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
No changes detected in app 'service_bus'

在我所有的模型中,我都有类似的东西

class APSettings(models.Model):
    ...
    class Meta:
        db_table = u'APSettings'
        app_label = 'service_bus'

我可能会错过什么?

【问题讨论】:

    标签: python django django-models django-migrations


    【解决方案1】:

    您需要先运行migrate 命令来搭建数据库架构。然后,您可以为每个应用程序运行makemigrations。有关更多信息,请查看Django tutorial

    【讨论】:

      【解决方案2】:

      确保更新您的 models.py 文件以实际导入模型。例如,在 models.py 中,您将拥有 from service_bus.models.audience import *。管理脚本遍历该文件,导入 Audience.py 中的所有模型并检测其中的更改。如果您没有将新模型添加到 models.py,那么管理脚本将不会知道模型文件中的新模型。

      【讨论】:

        猜你喜欢
        • 2014-09-14
        • 1970-01-01
        • 1970-01-01
        • 2016-07-09
        • 2021-07-07
        • 2014-12-24
        • 2016-06-19
        相关资源
        最近更新 更多