运行时错误:模型类 Himalayadashbords.clients.models.Client 未声明显式 app_label 并且不在 INSTALLED_APPS

问题描述

我正在使用千篇一律的代码,我遇到了这个错误: 客户端/apps.py:

from django.apps import AppConfig


class ClientConfig(AppConfig):
    name = 'clients'

settings.py:

LOCAL_APPS = [
    "himalayadashbords.users.apps.UsersConfig","himalayadashbords.clients.apps.ClientConfig","himalayadashbords.queries.apps.QueriesConfig","himalayadashbords.dashboard.apps.DashboardConfig",# Your stuff: custom apps go here
]

clients/models.py:

from django.db import models

class Client(models.Model):
    name = models.CharField(max_length=50,unique=True)
    QBO_id = models.CharField(max_length=100)
    QBO_refreshtoken = models.CharField(max_length=100)
    fiscalmonth = models.IntegerField(default=1)

    def __str__(self):
        return self.name

仪表板/views.py:

from himalayadashbords.clients.models import Client
from himalayadashbords.queries.QBOQueries.qQBOInvRevenues import avNEclients

listofcpy = Client.objects.all().only("pk","name")

错误调试:

  File "/Users/xxx/PycharmProjects/cool/himalayadashbords/himalayadashbords/clients/urls.py",line 3,in <module>
    from .views import (
  File "/Users/xxx/PycharmProjects/cool/himalayadashbords/himalayadashbords/clients/views.py",line 8,in <module>
    from .models import Client
  File "/Users/xxx/PycharmProjects/cool/himalayadashbords/himalayadashbords/clients/models.py",in <module>
    class Client(models.Model):
  File "/Users/xxx/PycharmProjects/cool/himalayadashbords/venv/lib/python3.8/site-packages/django/db/models/base.py",line 113,in __new__

我已经试过了:

  1. 使用 name = Himalayadashbords.clients 和 verbose="clients" 更改 apps.py
  2. 尝试在模块客户端中进行查询而不是将其导入仪表板,但我遇到了同样的问题

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)