gpt4 book ai didi

django - (fields.E300) 字段定义与模型的关系,该模型要么未安装,要么是抽象的

转载 作者:行者123 更新时间:2023-12-02 13:48:33 24 4
gpt4 key购买 nike

我的 Django 项目“aplikacja”中安装了 2 个应用程序

第一个名为:“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”

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 应用程序中选择这些值。

这个问题可以解决吗?

最佳答案

您应该将应用程序名称添加到 FK 定义中的相关模型名称中:

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

关于django - (fields.E300) 字段定义与模型的关系,该模型要么未安装,要么是抽象的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28626648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com