【发布时间】:2015-02-18 13:03:09
【问题描述】:
我已经阅读了Peewee MySQL API documentation 和this question;但是,我不明白的是如何使用 Peewee 连接到数据库中的指定表。基本上我要做的就是连接到名为as_schema 的数据库中名为Persons 的表,设置某种基本的对象关系映射,并打印出所有条目的aNum 列值。
我试图读取的表 Persons 具有以下列:
- varchar 称为
aNum - bool 称为
access - bool 称为
ajar - bool 称为
ebr - 日期调用
weekof
我的代码包含以下内容:
import peewee
from peewee import *
db = MySQLDatabase('as_schema', user='root',passwd='')#this connection path works perfectly, tried it using the standard MySQLdb.connect
class Person(Model):
class Meta:
database = db
class User(Person):
aNum = CharField()
Person.create_table()
person = User(aNum = 'a549189')
person.save();
for person in Person:
print person.aNum
我得到的错误是:
【问题讨论】:
-
到目前为止,我发现使用 Pwiz 和 migrate 功能可能是个好主意peewee.readthedocs.org/en/latest/peewee/playhouse.html#pwiz