Auto Field:
int auto increment, must fill in the parameters primary_key = True
If you do not write AutoField, it will automatically create a column called id column
from django.db import models class Person(models.Model): id = models.AutoField(primary_key=True) # 自增的 id 主键
CharField:
Character type, you must provide max_length parameters, max_length represents the maximum character length
from django.db import models class Person(models.Model): id = models.AutoField(primary_key=True) # 自增的 id 主键 name = models.CharField(max_length=32)
IntegerField:
Integer type, the range -2147483648 2147483647
from django.db import models class Person(models.Model): id = models.AutoField(primary_key=True) # 自增的 id 主键 name = models.CharField(max_length=32) age = models.IntegerField()
DateField:
Date field, the date format YYYY-MM-DD, corresponding to the Python datetime.date ()
from django.db import models class Person(models.Model): id = models.AutoField(primary_key=True) # 自增的 id 主键 name = models.CharField(max_length=32) age = models.IntegerField() birthday = models.DateField(auto_now_add=True)
DatetimeField, DateField, TimeField three time fields, can be set auto_now_add, auto_now properties
auto_now_add = True, it will create a data record when the current time is assigned to the field
auto_now = True, then, each time updating the data record will be used to update the field
DateTimeField:
Time field, the format YYYY-MM-DD HH: MM [: ss [.uuuuuu]] [TZ], corresponding to the Python A datetime.datetime ()
Excuting an order:
manage.py@mysite2 > makemigrations app01 manage.py@mysite2 > migrate app01
To look over database
adding data
Add only name, age field
DateField add date of this data