Django的。为什么不在DB中创建日期字段?

时间:2014-05-19 19:45:57

标签: django django-models

我有一个模特:

class Users_data (models.Model):
    first_name_user = models.CharField(max_length=45, verbose_name="")
    e_mail = models.EmailField(max_length=45, verbose_name="")
    e_mail2 = models.EmailField(max_length=45, verbose_name="")
    password = models.CharField(max_length=45, verbose_name="")
    password2 = models.CharField(max_length=45, verbose_name="")
    bir_date = models.DateField(auto_now=True, verbose_name="", blank=True, null=True),

    class Meta:
        managed = True
        db_table = 'Users_data'

为什么不创建列 - bir_date但是所有其余列都已创建?

1 个答案:

答案 0 :(得分:3)

由于字段定义后面有逗号,因此bir_date被视为tuple。查看逗号如何更改变量的类型:

>>> s = "test"
>>> type(s)
<type 'str'>
>>> s = "test",
>>> type(s)
<type 'tuple'>

删除逗号,Django将“选择”该字段:

bir_date = models.DateField(auto_now=True, verbose_name="", blank=True, null=True)