Python 字符串模型引用的格式必须为';app_label.ModelName';向模型添加外键字段时出错

Python 字符串模型引用的格式必须为';app_label.ModelName';向模型添加外键字段时出错,python,django,django-models,foreign-keys,Python,Django,Django Models,Foreign Keys,我在company/sales/内部有一个应用程序客户,其应用程序标签为“company.sales.customer”。 此应用程序在models.py中包含一个模型客户 我想将此模型作为外键链接到另一个应用程序“订单” “订单”的models.py: from django.db import models class Order(models.Model): party = models.ForeignKey('company.sales.customer.Customer',

我在company/sales/内部有一个应用程序客户,其应用程序标签为“company.sales.customer”。 此应用程序在models.py中包含一个模型客户

我想将此模型作为外键链接到另一个应用程序“订单”

“订单”的models.py:

from django.db import models
 
class Order(models.Model):
    party = models.ForeignKey('company.sales.customer.Customer', on_delete=models.CASCADE)
    --other fields--
“客户”的apps.py:

from django.apps import AppConfig


class CustomerConfig(AppConfig):
    name = 'company.sales.customer'
    label = 'company.sales.customer'
settings.py:

INSTALLED_APPS = [
----,
'company.sales.customer'
]
运行
python manage.py makemigrations
时,出现以下错误:

ValueError: Invalid model reference 'company.sales.customer.Customer'. String model references must be of the form 'app_label.ModelName'.

您型号的
app\u标签可能是
customer
,因此
'customer.customer'
。您可以使用Django shell中的
Customer.\u meta.app\u label
检查此问题……您的型号的
app\u label
很可能是
Customer
,因此
'Customer.Customer'
。您可以通过Django shell中的
Customer.\u meta.app\u label
检查这一点。。。