Django系列6:Model简介,ORM,字段类型,约束

1、Django模型(Model)








models.py

class Person(models.Model):
    p_name = models.CharField(max_length=16,unique=True)
    p_age = models.IntegerField(default=18,db_column='age')
    #False 代表男,True代表女
    p_sex= models.BooleanField(default=False,db_column='sex')

    class Meta:
        db_table='People'

DDL

create table People
(
  id     int auto_increment
    primary key,
  p_name varchar(16) not null,
  age    int         not null,
  sex    tinyint(1)  not null,
  constraint p_name
  unique (p_name)
);

posted @ 2020-02-04 15:54  xidianzxm  阅读(180)  评论(0编辑  收藏  举报