为什么Django不能从模型中创建完整的表?

时间:2010-02-16 04:19:17

标签: database django django-models syncdb manage.py

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

这是我的models.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)

2 个答案:

答案 0 :(得分:1)

如果您没有任何数据,可以删除表格,也可以使用可用于迁移的django-south

答案 1 :(得分:1)

太容易了。每个字段声明后都有很多冗余逗号。我删除了那些,一切正常。

感谢您的回复。