Comments (12)
Thanks for the reply - worked it out in the end:
I had a database session open in a flask shell, which was preventing alembic from obtaining a lock and therefore running the update - finished the session and then the migration worked fine.
from flask-migrate.
For those who want to run alembic upgrade when app is running, add the following code in your project's app file.
@app.teardown_appcontext
def shutdown_session(exception=None):
db.remove()
the variable db is the database session from your database setting file. so you should import it first.
you have to remove the session (return it to the pool) after each request.
When alembic runs, it uses flask's app context, and the currently running app is holding all connections, which means there are no available connections for alembic to use.
https://flask.palletsprojects.com/en/1.0.x/appcontext/
from flask-migrate.
Yep, this should have been obvious, ha!.
I had around 3 terminals open one for vim, one for the flask server and the other for the flask shell, still I didn't notice. palm to the face.
from flask-migrate.
This is happening also because of thread with an infinite loop (intentionally for checking some kind of event),
from flask-migrate.
Just adding this as a potential cause:
For me, it was a docker container running in the background that was locking the database...
from flask-migrate.
What was your fix? I'm having the same issue!
from flask-migrate.
I can't quite remember, but I reckon you could squash the migration by deleting it (since it's not committed) and redoing the migrate and upgrade steps again.
from flask-migrate.
@authentik8 Had the same problem, thanks ! 👍
P.S. I noticed that you found the fix after 2 days. Just wondering, did you let it be like that for two days ?
from flask-migrate.
No problem, put up an explanation for exactly that reason!
In reply to your PS, no (I was out for one of the middle days anyway!) - I got as far as working out that if I killed and recreated my tmux session whenever it hung then I could get it to work. Obviously the issue was intermittent as I only had a flask shell open some of the time, but it worked "well enough" for a while.
Eventually I got tired of having to reconfigure all of my panes after every time it hung, so I decided to stop developing more stuff until I resolved it. Took me about 15 minutes of playing around with different things until I could isolate the cause (which then made sense, reading the SQLAlchemy docs on how sessions work).
from flask-migrate.
@samakshjain Thank you for saying so. I use gnu screen as well, and that was the exact problem! Also facepalm
from flask-migrate.
For me, it's because the type tinyint and bool are the same thing in mysql but alembic sees them differently, so every time I upgrade it stuck. See here for more detail.
from flask-migrate.
Same issue - for me I had one of my tables misspelled such as in
tablename = 'nlp_words_in_topics_t'
Check syntax, spelling errors
from flask-migrate.
Related Issues (20)
- Upgrade problems; Online migration expected to match one row error HOT 1
- Alembic upgrade head in infinite loop HOT 1
- Migrations sometimes end with status 1 HOT 4
- How to check if models are in sync with generated migrations? HOT 1
- Type hints HOT 2
- [4.0] app factory is called before click groups HOT 6
- flask db migrate taking ~30min to autogenerate and throwing unrelated warnings HOT 2
- How is this possible?
- Failure to run flask db migrate after upgrade 3.1 -> 4.0 HOT 4
- Custom Template is not included in the sdist HOT 1
- Compatibility with sqlalchemy v2 HOT 5
- DeprecationWarning: 'get_engine' is deprecated HOT 5
- Enum Field changes, but no changes in schema detected when run "flask db migrate" HOT 1
- Do not automatically import of sqlalchemy_utils HOT 1
- The pgvector vector field cannot generate a normal migration script HOT 1
- An error was reported during migration
- [Feature request] Move `process_revision_directives` to `alembic_ctx_kwargs` HOT 2
- Problems connecting to Postsgress Because of no encryption HOT 5
- No such command 'db'
- db.create_all() not working with PostgreSQL on windows platform HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-migrate.