I'm trying to use Peewee with Flask, but I don't understand why my database connection does 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
from 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 *
from . import db
database = dbclass UnknownField(object):def __init__(self, *_, **__): pass
class BaseModel(Model):class Meta:database = databaseclass Tbcategory(BaseModel):insert_dt = DateTimeField()name = CharField()class Meta:db_table = 'tbcategory'
I generated models.py with pwiz.
If I try to use it on the interactive console I get the error on the title. If I change the line on models.py from database=db to the original one created by pwiz:
db = MySQLDatabase('test', **{'host': '127.0.0.1', 'password': 'root', 'user': 'root'})
everything works fine. I can't find for the life of me an example on internet. Either the configuration is all in the app or it's outside in a config.py file but with sqlite or some orther slightly different usages. Should I stop using Database() from flask_peewee and using the MySQLDatabase directly? How do i use an external file with the configuration? Note that I use 127.0.0.1 on one method, and no host specification on the other. I did copy from peewee-flask's website.