Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(fields.E300) Field defines a relation with model which is either not installed, or is abstract

I have 2 apps installed in my Django Project "aplikacja"

The first one named: "Godzina"

from django.db import models

class Godzina (models.Model):
        GODZINA = (
        ('19', '19'),
        ('20', '20'),
        ('21', '21'),
        )
        godzina = models.CharField(max_length=6, choices=GODZINA, verbose_name='jezyk')

and the second named: "UserProfile"

from django.db import models
from django.contrib.auth.models import User
from godzina.models import Godzina

class UserProfile(models.Model):
    czas = models.ForeignKey('Godzina')   
    user = models.OneToOneField(User)

I'm getting such error:

userprofile.UserProfile.czas: (fields.E300) Field defines a relation with model 'Godzina', which is either not installed, or is abstract.

What does it mean? I would like that User can only pick such time as an administrator put in the app "Godzina" For example I'm defining hours 19 pm, 20 pm and then user can choose those values in UserProfile app

Is it possible to fix this problem?

like image 811
Anna K Avatar asked Feb 20 '15 10:02

Anna K


3 Answers

You should add the app name to the related model name in the FK definition:

czas = models.ForeignKey('firstapp.Godzina') 
like image 123
catavaran Avatar answered Nov 15 '22 00:11

catavaran


A generic information when using the models from one app to another app is

model_variable = models.ForeignKey('the_appname.the_model_class_name')

In this case,for the Django-project “aplikacja”, for the second app(UserProfile) it should be :

czas = models.ForeignKey(‘Godzina.Godzina') 

After this I suggest you remove all the files in the migrations folder(under the apps you created: Godzina and UserProfile) except the init file. Also remove the SQLite file. Then run Python manage.py makemigrations and python manage.py migrate. These steps should most probably fix the problem.

like image 5
Winston John Paiva Avatar answered Nov 15 '22 01:11

Winston John Paiva


I had the same error, and it was an issue due to the similar names of the classes.

like image 2
Daniel Mandelblat Avatar answered Nov 15 '22 00:11

Daniel Mandelblat