python peewee
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python peewee相关的知识,希望对你有一定的参考价值。
from peewee import *
mysql_db = MySQLDatabase(
'test',
host='localhost',
port=3306,
user='root',
passwd=''
)
mysql_db.connect()
class MySQLModel(Model):
class Meta:
database = mysql_db
class Person(MySQLModel):
name = CharField()
birthday = DateField()
is_relative = BooleanField()
class Pet(MySQLModel):
owner = ForeignKeyField(Person, related_name='pets')
name = CharField()
animal_type = CharField()
if __name__ == '__main__':
# mysql_db.create_tables([Person, Pet])
pass
以上是关于python peewee的主要内容,如果未能解决你的问题,请参考以下文章