Model has either not been installed or is abstract
When I try to migrate my code I get this error. Here are my code and classes:
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"
Here is the error I get:
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.
You're unnecessarily confusing yourself by having these in separate files within the same app.
But your issue is caused by the way you're referenced the target model. You don't use the full module path to the model: you just use 'app_name.ModelName'. So in your case it should be:
Another issue can be when using multiple models in separate files missing statement like:
class Meta: app_label = 'core_backend'
You can also get this error if there a bug in your models file that prevents it from loading properly. For example, in models.py
from third_party_module_i_havent_installed import some_method
I hit this error when I didn't put a third-party app in my INSTALLED_APPS setting yet.