首页 > 解决方案 > 导入错误以某种方式与 app_labels 相关

问题描述

Django==2.2.3

蟒蛇 3.7

我收到此错误:

    from yandex.models import YandexGoals
ImportError: cannot import name 'YandexGoals' from 'yandex.models' (/home/michael/PycharmProjects/ads1/ads_manager/yandex/models.py)

当我在发生异常时停止在我的 IDE 中(即,我在任何异常时停止)并评估表达式“从 yandex.models 导入 YandexGoals”,我得到这个:

RuntimeError: Model class yandex_campaigns.models.YandexCampaignCommonTemplate doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

嗯,消息不同。让我们调查一下我们有什么:

INSTALLED_APPS = [
   ...
   'yandex',
    'yandex_campaigns',
]

yandex/models.py

class YandexGoals(models.Model):
    ...

yandex/apps.py

class YandexConfig(AppConfig):
    name = 'yandex'

yandex_campaigns.apps.py

class YandexCampaignsConfig(AppConfig):
    name = 'yandex_campaigns'

尽我所能,我看不出这里有任何缺陷。你能给我一脚吗?

标签: django

解决方案


推荐阅读