python – 模型未安装或是抽象的

当我尝试迁移我的代码时,我收到此错误.
这是我的代码和类:

from django.db import models
from core.models import Event

class TicketType(models.Model):
    name = models.CharField(max_length=45)
    price = models.DecimalField(max_length=2, decimal_places=2, max_digits=2)
    type = models.CharField(max_length=45)
    amount = models.IntegerField()
    event = models.ForeignKey(Event)

class Meta:
    app_label = "core"


import datetime
from django.core.serializers import json
from django.db import models
from core.models import User


class Event(models.Model):
    page_attribute = models.TextField()
    name = models.TextField(max_length=128 , default="New Event")
    description = models.TextField(default="")
    type = models.TextField(max_length=16)
    age_limit = models.IntegerField(default=0)
    end_date = models.DateTimeField(default=datetime.datetime.now())
    start_date = models.DateTimeField(default=datetime.datetime.now())
    is_active = models.BooleanField(default=False)
    user = models.ForeignKey(User)
    ticket_type=models.ForeignKey('core.models.ticket_type.TicketType')

    class Meta:
            app_label = "core"

这是我得到的错误:

CommandError: One or more models did not validate:
core.event: ‘ticket_type’ has a relation with model core.models.ticket_type.TicketType,
which has either not been installed or is abstract.

通过在同一个应用程序中的单独文件中使用这些内容,您会不必要地混淆自己.

但是您的问题是由您引用目标模型的方式引起的.您不使用模型的完整模块路径:您只需使用’app_name.ModelName’.所以在你的情况下它应该是:

ticket_type=models.ForeignKey('core.TicketType')
相关文章
相关标签/搜索