python - Peewee and Flask : 'Database' object has no attribute 'commit_select' -
i'm trying use peewee flask, don't understand why database connection not work.
config.py
class configuration(object): database = { 'name': 'test', 'engine': 'peewee.mysqldatabase', 'user': 'root', 'passwd': 'root' } debug = true secret_key = 'shhhh'
app/init.py
from flask import flask flask_peewee.db import database app = flask(__name__) app.config.from_object('config.configuration') db = database(app) import views,models
app/models.py
from peewee import * . import db database = db class unknownfield(object): def __init__(self, *_, **__): pass class basemodel(model): class meta: database = database class tbcategory(basemodel): insert_dt = datetimefield() name = charfield() class meta: db_table = 'tbcategory'
i generated models.py pwiz.
if try use on interactive console error on title. if change line on models.py database=db original 1 created pwiz:
db = mysqldatabase('test', **{'host': '127.0.0.1', 'password': 'root', 'user': 'root'})
everything works fine. can't find life of me example on internet. either configuration in app or it's outside in config.py file sqlite or orther different usages. should stop using database() flask_peewee , using mysqldatabase directly? how use external file configuration? note use 127.0.0.1 on 1 method, , no host specification on other. did copy peewee-flask's website.
you using database
wrapper object. @ actual peewee database object, use:
app.config.from_object('config.configuration') db = database(app) database = db.database # database actual peewee database obj.
in models code:
from peewee import * . import database # import actual peewee database
Comments
Post a Comment