小编Wad*_*nde的帖子

为什么我在我的 Django 项目中不断收到这个“名称'模型'未定义”错误?

我已经查看了这个主题下的 stackoverflow 问题,并且我将 Trainer 类移到了 Class_Training 类的上方,但是当我输入“manage.py create”时,我仍然收到相同的“name 'Model' is not defined”错误超级用户”在我的命令提示符下。

另外,我很难迁移我的模型。我尝试过“django-admin makemigrations training”,但无法识别 django-admin;和 'manage.py makemigrations training' 但 makemigrations 未被识别。

如何迁移我的模型?

这是我的代码:

    #from django.db import models
 from django_pg import models

# Create your models here.
TRAINING_TYPE_CHOICES = (
    ('AC', 'Armed Combat'),
    ('UC', 'Unarmed Combat'),
    ('P', 'Piloting'),
    ('O', 'Other'),
)

GENDER_CHOICES = (
    ('F', 'Female'),
    ('M', 'Male'),
    ('U', 'Unspecified'),
    )
OUTCOME_CHOICES = (
    ('P', 'Pass'),
    ('F', 'Fail'),
    )

class Trainer(models, Model):
    first_name = models.CharField(max_length = 25)
    surname = models.CharField(max_length …
Run Code Online (Sandbox Code Playgroud)

python django model nameerror

5
推荐指数
1
解决办法
4万
查看次数

Django AttributeError:'Alias'对象没有属性'urls'

我刚刚为我的英雄应用程序写完了我的模型:

这是我的Heroes应用程序的models.py文件:

来自django.db导入模型

# Create your models here.
class Hero(models.Model):
    codename = models.CharField(max_length = 30)
    profilePic = models.ImageField(blank=True) #blank makes this optional

    def __str__(self):
        return (self.codename)

class Stats(models.Model):
    heroID = models.ForeignKey('Hero')
    height = models.CharField(max_length = 10)
    weight = models.CharField(max_length = 10)
    STATS_CHOICES = (
    ('1', 'Extremely Low'),
    ('2', 'Very Low'),
    ('3', 'Low'),
    ('4', 'Average'),
    ('5', 'Good'),
    ('6', 'Above Average'),
    ('7', 'High'),
    ('8', 'Very High'),
    ('9', 'Super Human'),
    ('10', 'Above and Beyond'))
    powers = models.CharField(max_length = 5, choices = STATS_CHOICES)
    intelligence …
Run Code Online (Sandbox Code Playgroud)

python migration django django-models

5
推荐指数
2
解决办法
3718
查看次数

标签 统计

django ×2

python ×2

django-models ×1

migration ×1

model ×1

nameerror ×1