Code Monkey home page Code Monkey logo

Comments (12)

jwindridge avatar jwindridge commented on May 22, 2024 61

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.

kangju1 avatar kangju1 commented on May 22, 2024 3

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.

samakshjain avatar samakshjain commented on May 22, 2024 1

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.

rnm-patel avatar rnm-patel commented on May 22, 2024 1

This is happening also because of thread with an infinite loop (intentionally for checking some kind of event),

from flask-migrate.

reinoldus avatar reinoldus commented on May 22, 2024 1

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.

jwindridge avatar jwindridge commented on May 22, 2024

What was your fix? I'm having the same issue!

from flask-migrate.

mattgathu avatar mattgathu commented on May 22, 2024

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.

samakshjain avatar samakshjain commented on May 22, 2024

@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.

jwindridge avatar jwindridge commented on May 22, 2024

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.

Sparrow1029 avatar Sparrow1029 commented on May 22, 2024

@samakshjain Thank you for saying so. I use gnu screen as well, and that was the exact problem! Also facepalm

from flask-migrate.

jabbawockeez avatar jabbawockeez commented on May 22, 2024

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.

edwardmoradian avatar edwardmoradian commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.