Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

django - (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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...