I am trying to implement python-social-auth in Flask. I guessed tons of kinks while trying to interpret 4 textbooks and a complete flask book at the same time, and I feel like I've reached my dead end with Flask-migrate.
I am currently using the following code to create the tables necessary for python-social-auth to work in flask-sqlalchemy environment.
from social.apps.flask_app.default import models
models.PSABase.metadata.create_all(db.engine)
Now they explicitly use some form of their own base, not related to my actual db object. This, in turn, causes Flask-Migrate to completely skip these tables and delete them during migration. Now, obviously, I can remove these db drops from each delete, but I can imagine that this is one of those things that will be forgotten at some point, and suddenly I no longer have OAuth connections.
I got this solution to work using (and modifying) the manage.py-syncdb command suggested by python-social-auth Flash example
Miguel Greenberg, author of Flask-Migrate magazine, answers here , which seems to be very similar to mine.
The closest I could find when the stack overflowed was this one , but it did not shed too much light on the whole thing for me, and the answer was never accepted (and I can not get it to work, I tried several times)
For reference, here is my manage.py:
from flask.ext.script import Server, Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from app import app, db
manager = Manager(app)
manager.add_command('runserver', Server())
manager.add_command('shell', Shell(make_context=lambda: {
'app': app,
'db_session': db.session
}))
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
@manager.command
def syncdb():
from social.apps.flask_app.default import models
models.PSABase.metadata.create_all(db.engine)
db.create_all()
if __name__ == '__main__':
manager.run()
And to clarify, the db init / migrate / upgrade commands only create my user table (and its migration), but not social, and the syncdb command works for python-social-auth tables.
github, Flask-Migrate, , PSABase, db-, Migrate.
.
( , . , , , , , . - SO, , )