Issue: Issue using FlaskDB and create_tables
Author: bwghughes
State: closed
Created: 2016-11-08 05:07:12

With the following code:

```python
import os
from datetime import date

from flask import Flask, request, render_template
from flask.views import MethodView
from peewee import *
from playhouse.flask_utils import FlaskDB

import logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)

db_wrapper = FlaskDB()

class JobCodeEntry(db_wrapper.Model):
    date = DateField(default=date.today)
    code = CharField()

    class Meta:
        database = db_wrapper


class JCRTwilioHook(MethodView):
    def get(self):
        return render_template('index.html', entries=JobCodeEntry.select())

    def post(self):
        JobCodeEntry.create({'code': request.form.get('Body')})
        return 'OK'


def create_app():
    app = Flask(__name__)
    app.config['DATABASE'] = os.getenv('DATABASE_URL')
    db_wrapper.init_app(app)
    db_wrapper.database.create_tables([JobCodeEntry])
    app.add_url_rule('/jcr/', view_func=JCRTwilioHook.as_view('jcr'))
    return app


def main():
    app = create_app()
    app.run(debug=True)

if __name__ == '__main__':
    main()
```

I get the following error:

```python
Traceback (most recent call last):
  File "app.py", line 46, in <module>
    main()
  File "app.py", line 42, in main
    app = create_app()
  File "app.py", line 37, in create_app
    db_wrapper.database.create_tables([JobCodeEntry])
  File "/Users/ben/.pyenv/versions/jcr/lib/python3.5/site-packages/peewee.py", line 3772, in create_tables
    create_model_tables(models, fail_silently=safe)
  File "/Users/ben/.pyenv/versions/jcr/lib/python3.5/site-packages/peewee.py", line 5176, in create_model_tables
    m.create_table(**create_table_kwargs)
  File "/Users/ben/.pyenv/versions/jcr/lib/python3.5/site-packages/peewee.py", line 4853, in create_table
    if db.sequences and pk is not False and pk.sequence:
AttributeError: 'FlaskDB' object has no attribute 'sequences'
```

It seems the API either isn't what I expected, or calling create_tables on the underlying database doesn't work as I thought.

Thanks in advance !!


Subclassing `db_wrapper.model` obviates the need for a Meta: database definition. Furthermore, your "Meta" database should always be the un-wrapped Peewee db.

This is sufficient, though -- just remove the "Meta":

```
class JobCodeEntry(db_wrapper.Model):
    date = DateField(default=date.today)
    code = CharField()
```


Thanks Charles !!

On Tue, 8 Nov 2016 at 07:18, Charles Leifer notifications@github.com
wrote:

> Subclassing db_wrapper.model obviates the need for a Meta: database
> definition. Furthermore, your "Meta" database should always be the
> un-wrapped Peewee db.
> 
> This is sufficient, though -- just remove the "Meta":
> 
> class JobCodeEntry(db_wrapper.Model):
>     date = DateField(default=date.today)
>     code = CharField()
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> https://github.com/coleifer/peewee/issues/1121#issuecomment-259055392,
> or mute the thread
> https://github.com/notifications/unsubscribe-auth/AAAeDgK7eVEjD9YEZ4ZZF-R4pR_3Twbcks5q8BQ5gaJpZM4KsCiz
> .