librelist archives

« back to archive

Flask-SQLAlchemy models in separate file problem

Flask-SQLAlchemy models in separate file problem

From:
Alex
Date:
2011-02-24 @ 10:23
Hello,

I've looked to flask-feedback/manage.py file that works fine.
https://github.com/mitsuhiko/flask-feedback

When you use Flask-SQLAlchemy and put models declaration to separate
file (not using "everything in one file" approach) it causes problems
with DB configuration in manage.py
Looks like application db  is not populated in this case.

Can you, please, provide an example of:

from flaskext.script import Manager
from feedback import app, db
manager = Manager(app)
@manager.command
def initdb():
    db.create_all()
@manager.command
def dropdb():
    db.drop_all()
if __name__ == '__main__':
    manager.run()

That will work when your Flask-SQLAlchemy models are in separate file?

Thanks a lot.

Thanks,
Alex

Re: [flask] Flask-SQLAlchemy models in separate file problem

From:
Armin Ronacher
Date:
2011-02-24 @ 10:34
Hi,

On 2/24/11 11:23 AM, Alex wrote:
> When you use Flask-SQLAlchemy and put models declaration to separate
> file (not using "everything in one file" approach) it causes problems
> with DB configuration in manage.py
> Looks like application db  is not populated in this case.
You have to make sure that the module that implements the models is 
imported somewhere.  For instance just add this statement to either your 
manage.py or your application itself:

import myapplication.models


Regards,
Armin