coleifer / flask-peewee

flask integration for peewee, including admin, authentication, rest api and more
http://flask-peewee.readthedocs.org/
MIT License
777 stars 179 forks source link

raise NotImplementedError #190

Closed redstoneleo closed 7 months ago

redstoneleo commented 7 months ago

Tested with the following code on win11 and Python 3.9.15 (main, Oct 11 2022, 15:28:02) [MSC v.1929 64 bit (AMD64)] on win32, got

Traceback (most recent call last):
  File "F:\BaiduNetdiskDownload\ConsumerSoftwareProject\py-bot-flask\peewee-orm.py", line 32, in <module>
    auth.User.create_table(fail_silently=True)
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 7041, in create_table
    cls._schema.create_all(safe, **options)
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 6143, in create_all
    self.create_table(safe, **table_options)
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 5994, in create_table
    self.database.execute(self._create_table(safe=safe, **options))
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 3299, in execute
    return self.execute_sql(sql, params)
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 3290, in execute_sql
    cursor = self.cursor()
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 3280, in cursor
    self.connect()
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 3232, in connect
    self._state.set_connection(self._connect())
  File "C:\Users\22815\AppData\Local\Programs\Python\Python39\lib\site-packages\peewee.py", line 3218, in _connect
    raise NotImplementedError
NotImplementedError

import datetime
from flask import Flask
from flask_peewee.auth import Auth
from flask_peewee.db import Database
from peewee import *

# configure our database
DATABASE = {
    'name': 'example.db',
    'engine': 'peewee.SqliteDatabase',
}
DEBUG = True
SECRET_KEY = 'ssshhhh'

app = Flask(__name__)
app.config.from_object(__name__)

# instantiate the db wrapper
db = Database(app)

class Note(db.Model):
    message = TextField()
    created = DateTimeField(default=datetime.datetime.now)

# create an Auth object for use with our flask app and database wrapper
auth = Auth(app, db)

if __name__ == '__main__':
    auth.User.create_table(fail_silently=True)
    Note.create_table(fail_silently=True)

    app.run()
coleifer commented 7 months ago

The problem is:

from flask_peewee.db import Database
from peewee import *

You are importing the peewee.Database which is shadowing the flask_peewee.db.Database. This should fix it:

from peewee import *
from flask_peewee.db import Database
redstoneleo commented 7 months ago

Thanks ! The code actually comes from http://docs.peewee-orm.com/projects/flask-peewee/en/latest/getting-started.html#adding-users-to-the-site so you should update the doc too.