0

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 a a 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:

  • varchar called aNum
  • bool called access
  • bool called ajar
  • bool called ebr
  • date called 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: enter image description here

Community
  • 1
  • 1
beckah
  • 1,543
  • 6
  • 28
  • 61
  • So far what I've found is that maybe using Pwiz and the migrate function may be a good idea http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#pwiz – beckah Dec 19 '14 at 17:35

1 Answers1

0
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

coleifer
  • 24,887
  • 6
  • 60
  • 75