Skip to content

Is invoking SQLAlchemy's declarative_base()—bypassing Flask-SQLAlchemy's models—a sanctioned workflow? #534

Answered by miguelgrinberg
john-bodley asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, I see now that what I suggested is not really possible. The project in which I've done this was implemented with SQLAlchemy and Alembic directly, not with Flask and Flask-Migrate. That gives you more control over what gets imported. The flask command imports your Flask app, and to create this object pretty much everything must be imported.

Unfortunately I do not have any great ideas. I think every solution is going to be hacky. I think the only reasonable option is to avoid using models in migration scripts, which is actually what the vast majority of people do, what 99.9% of projects I have been involved with do, and what the automatic migration generator does as well.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@john-bodley
Comment options

@miguelgrinberg
Comment options

Answer selected by john-bodley
@john-bodley
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants