I have read the Peewee MySQL API documentation and this question ; however, what I do not understand is how to connect to a specified table in a db using Peewee. Essentially all I'm trying to do is connect to aa table called Persons
in a db called as_schema
, set up some sort of basic object-relational mapping, and print out all entries' aNum
column values.
My table Persons
that I'm trying to read from has the following columns:
aNum
access
ajar
ebr
weekof
My code consists of the following:
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
The error I'm getting is:
class Person(Model):
class Meta:
database = db
db_table = 'Persons' # Add this.
In the docs, you can find a list of supported meta options:
http://docs.peewee-orm.com/en/latest/peewee/models.html#model-options-and-table-metadata
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.