![](/img/trans.png)
[英]Trying to connect to Microsoft SQL database with Peewee (python)
[英]Specifying Table to Connect to with Python Peewee
我已经阅读了Peewee MySQL API文档和这个问题 ; 但是,我不明白的是如何使用Peewee连接到db中的指定表。 基本上,我想做的就是连接到名为as_schema
的数据库中名为Persons
表,设置某种基本的对象关系映射,并打印出所有条目的aNum
列值。
我要从中读取的表Persons
包含以下列:
aNum
access
ajar
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
我得到的错误是:
class Person(Model):
class Meta:
database = db
db_table = 'Persons' # Add this.
在文档中,您可以找到支持的元选项的列表:
http://docs.peewee-orm.com/zh-CN/latest/peewee/models.html#model-options-and-table-metadata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.