gpt4 book ai didi

database - 为什么 Django 不从模型创建完整表?

转载 作者:搜寻专家 更新时间:2023-10-30 20:32:34 25 4
gpt4 key购买 nike

我有 2 个模型。我运行 manage.py syncdb 但它只为 2 个模型创建 id 字段。如何让它生成剩余的字段?请指教。非常感谢您的帮助!

这是我的模型.py:

from django.db import models

GENDER_CHOICES = (
('M', 'Male')
, ('F', 'Female')
)

ACTIVATION_CHOICES = (
('Y', 'Activate')
, ('N', 'Inactive')
)

FULL_PART_CHOICES = (
('F', 'Full-time')
, ('P', 'Part-time')
)

# Create your models here.
class Teachers(models.Model):
id = models.AutoField(primary_key=True, null=False),
fname = models.CharField(max_length=15, null=False),
mname = models.CharField(max_length=15, null=False),
lname = models.CharField(max_length=15, null=False),
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, null=False),
nric = models.CharField(max_length=12, unique=True, null=False),
email = models.EmailField(max_length=40, unique=True, null=False),
dob = models.DateField(null=False),
unit = models.CharField(max_length=50, null=False),
block = models.CharField(max_length=50, null=False),
street = models.CharField(max_length=100, null=False),
postcode = models.CharField(max_length=10, null=False),
handphone = models.CharField(max_length=16, unique=True, null=False),
homephone = models.CharField(max_length=16, null=False),
activated = models.CharField(max_length=1, choices=ACTIVATION_CHOICES, null=False),
date_ttc = models.DateField(null=False),
full_part = models.CharField(max_length=1, choices=FULL_PART_CHOICES, null=False),
nonce = models.CharField(max_length=40, unique=True, null=False),
passwd = models.CharField(max_length=40, null=False),
created_at = models.DateTimeField(auto_now_add=True, null=False),
updated_at = models.DateTimeField(auto_now=True, null=False),

def __unicode__(self):
return "Teacher %s %s %s" % (self.fname, self.mname, self.lname)

# Create your models here.
class Admins(models.Model):
id = models.AutoField(primary_key=True, null=False),
fname = models.CharField(max_length=15, null=False),
mname = models.CharField(max_length=15, null=False),
lname = models.CharField(max_length=15, null=False),
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, null=False),
nric = models.CharField(max_length=12, unique=True, null=False),
email = models.EmailField(max_length=40, unique=True, null=False),
dob = models.DateField(null=False),
unit = models.CharField(max_length=50, null=False),
block = models.CharField(max_length=50, null=False),
street = models.CharField(max_length=100, null=False),
postcode = models.CharField(max_length=10, null=False),
handphone = models.CharField(max_length=16, unique=True, null=False),
homephone = models.CharField(max_length=16, null=False),
activated = models.CharField(max_length=1, choices=ACTIVATION_CHOICES, null=False),
nonce = models.CharField(max_length=40, unique=True, null=False),
passwd = models.CharField(max_length=40, null=False),
created_at = models.DateTimeField(auto_now_add=True, null=False),
updated_at = models.DateTimeField(auto_now=True, null=False),

def __unicode__(self):
return "Admin %s %s %s" % (self.fname, self.mname, self.lname)

最佳答案

如果表上没有任何数据,您可以删除这些表,或者使用可用于迁移的 django-south

关于database - 为什么 Django 不从模型创建完整表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2270602/

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