Code Monkey home page Code Monkey logo

Comments (9)

miguelgrinberg avatar miguelgrinberg commented on May 16, 2024 2

Well, hold on. There are only two possible reasons for Alembic to generate an empty migration, it shouldn't be that hard to at least determine which of the two you are experiencing:

  1. Alembic does not see your models
    1a. if the database has the tables in it then the generated migration drops all the tables.
    1b. if the database is empty then the generated migration is empty.
  2. Alembic sees your models, but the database tables are already created, resulting in an empty migration.

From your description it sounds like you are seeing case 1. Correct?

Now find the env.py file inside your migrations folder and using the answer to this question on SO see if your SQLAlchemy metadata object has any tables associated with it. If it doesn't, then for some reason your models aren't imported. As a quick proof/hack you can import them in the env.py file and see if that helps.

from flask-migrate.

miguelgrinberg avatar miguelgrinberg commented on May 16, 2024

Does it detect your migration if you move load_models() up right above the migrate = Migrate(app, db) line?

from flask-migrate.

BlackBears avatar BlackBears commented on May 16, 2024

It does not make a difference to move the import order.

I've come to believe that there circular import issues elsewhere in the app that I need to resolve.

Thanks, BTW, for all your contributions to the Flask community. Much appreciated.

from flask-migrate.

BlackBears avatar BlackBears commented on May 16, 2024

I was seeing case 1a initially. Then I dropped the tables and case 1b was the behavior I was noticing.

However, after doing some refactoring to simplify the model layer of the application - primarily to move all of the model classes into single module - everything seems to work as expected.

from flask-migrate.

jdell64 avatar jdell64 commented on May 16, 2024

Hate to post on a closed issue (3 years ago), but what would it mean if target_metadata.tables.keys() has values in it, but you can't get any migration files to generate?

from flask-migrate.

jdell64 avatar jdell64 commented on May 16, 2024

Ha, I figured it out... if you call db.create_all() that will create the db, and thus there will be no changes to detect.

from flask-migrate.

omogiafoh avatar omogiafoh commented on May 16, 2024

@miguelgrinberg, how do I solve case 2?

  • Alembic sees your models, but the database tables are already created, resulting in an empty migration.

from flask-migrate.

miguelgrinberg avatar miguelgrinberg commented on May 16, 2024

@omogiafoh there is nothing to solve. Your database matches your models, so there is no need to create a migration.

If you want to create migration as if your were starting a new project, then what you can do is backup and temporarily delete your tables from the database, generate the migration, then restore your tables back. You will finally do a flask db stamp head to mark the database as migrated.

from flask-migrate.

omogiafoh avatar omogiafoh commented on May 16, 2024

Thanks @miguelgrinberg. Turns out I had two instances of app. I got the solution from a comment you made here.

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.