(fields.E300) 字段定义了与未安装或抽象的模型的关系 [英] (fields.E300) Field defines a relation with model which is either not installed, or is abstract

查看:25
本文介绍了(fields.E300) 字段定义了与未安装或抽象的模型的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Django 项目aplikacja"中安装了 2 个应用

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

第一个名为:Godzina"

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')

第二个命名为:UserProfile"

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)

我收到这样的错误:

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

什么意思?我希望用户只能选择管理员在应用程序Godzina"中放置的时间例如我定义了晚上 19​​ 点、晚上 20 点,然后用户可以在 UserProfile 应用程序中选择这些值

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?

推荐答案

你应该在 FK 定义中将应用名称添加到相关模型名称中:

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

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

这篇关于(fields.E300) 字段定义了与未安装或抽象的模型的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆