Closed egorov-aleksey closed 8 years ago
Hi @meatbot. There is an example of flask app for flask and sqlalchemy https://github.com/omab/python-social-auth/tree/master/examples/flask_example . Please, look on manage.py file (https://github.com/omab/python-social-auth/blob/master/examples/flask_example/manage.py) you can find there a method syncdb
. If you run it '.manage.py syncdb' this command create all needed tables for you. Hopefully this advise will be useful.
@alexpantyukhin, I tried to use it. But i have a problem.
I add syncdb
command to my manage.py
:
from app.models import *
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def syncdb():
from social.apps.flask_app.default import models
models.PSABase.metadata.create_all(db.engine)
if __name__ == '__main__':
manager.run()
And python manage.py syncdb
successfully create relations social_auth_association
, social_auth_code
, social_auth_nonce
, social_auth_usersocialauth
. It is great!
But when i run python manage.py db migrate
I got a migration which removes social_auth_*
relations:
...
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('social_auth_nonce')
op.drop_table('social_auth_usersocialauth')
op.drop_table('social_auth_code')
op.drop_table('social_auth_association')
### end Alembic commands ###
...
What I should do? What am I doing wrong?
I guess I know what the problem. It seems you use flask_migrate
and social_auth
tables is not in the same session. That's why migration thinks that these tables are redundant. Did you made a call of init_social
?
I call init_social
in my models.py
module:
from app import app
from flask_sqlalchemy import SQLAlchemy
...
db = SQLAlchemy(app)
...
class User(db.Model):
...
init_social(app, db.session)
You about this?
I found perfect solution http://stackoverflow.com/a/35196770/2111562
How get database migrations for Flask app? Because I got error: sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "social_auth_usersocialauth" does not exist.
For Django app it is http://psa.matiasaguirre.net/docs/configuration/django.html#database
My Flask app manage.py:
What I should do for generate database migrations for Flask app?