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

发布于 2024-08-21 15:09:52 字数 3225 浏览 4 评论 0原文

我有 2 个型号。我运行manage.pysyncdb,但它只为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)

I have 2 models. I run manage.py syncdb but it creates only id fields for 2 models. How to make it generate the remaining fields? Please kindly advise. Your help is much appreciated!

Here's my 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心欲静而疯不止 2024-08-28 15:09:52

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

You can either drop the tables if you don't have any data on them or use django-south which you can use for migrating.

↙温凉少女 2024-08-28 15:09:52

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

感谢您的回复。

That was too easy. There were lots of redundant commas after each field declaration. I removed those and everything worked fine.

Thanks for your responses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文