from peewee import MySQLDatabase, Model
from peewee import CharField, DateField, IntegerField
from datetime import date
db = MySQLDatabase('spider', host="127.0.0.1", port=3306, user="root", password="ww1565223404")
class Person(Model):
id = IntegerField(primary_key=True)
name = CharField(max_length=20)
birthday = DateField(default=date(2000, 1, 1))
age = IntegerField(default=20)
class Meta:
database = db # This model uses the "people.db" database.
if __name__ == "__main__":
# 生成表
db.create_tables([Person])
# 添加数据
for i in range(10):
person = Person(id = i+1, name="user%d" % i, birthday=date(2000, 1 + i, 2 + i), age=20 + i)
person.save()
代码是这个,程序没有报错,删除主键可以正常写入数据