Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask db migrate/upgrade not responding #384

Closed
Victor7095 opened this issue Feb 8, 2021 · 10 comments
Closed

Flask db migrate/upgrade not responding #384

Victor7095 opened this issue Feb 8, 2021 · 10 comments
Labels

Comments

@Victor7095
Copy link

Hi, I deleted the migrations folder, then ran flask db init, then flask db migrate -m 'Test', but nothing happened, only got some messages:

INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

The command flask db upgrade also shows the same message but nothing else.

@miguelgrinberg
Copy link
Owner

Can you provide an example project that has this problem? I can't really tell you what's wrong, something is definitely missing but I don't know exactly what.

@ghost
Copy link

ghost commented Feb 11, 2021

@miguelgrinberg, I can reproduce this issue with flask-migrate==2.6.0. This seems to happen when the database is in a revision that is not found in the migrations. With flask-migrate==2.5.3 I get an error message "Can't locate revision identified by '...'", but flask-migrate==2.6.0 doesn't display any error.

Steps to reproduce:

> pip install flask-migrate==2.6.0
> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade xxx -> yyy
> rm migrations/yyy.py
> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
# NO ERROR RETURNED HERE
> pip install flask-migrate==2.5.3
> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
ERROR [root] Error: Can't locate revision identified by 'yyy'

@miguelgrinberg
Copy link
Owner

Why would you want to use an old release through? Old releases have to be installed from a requirements.txt file, because the dependencies might have changed since the release. In particular Alembic has been upgraded in a backwards incompatible way in this case.

@ghost
Copy link

ghost commented Feb 11, 2021

I would not want to use an old release. I just noticed this after updating to flask-migrate==2.6.0 (I'm using Alembic 1.5.4). Latest flask-migrate does not display an error message and fails silently when a revision can't be located. Previous version displays an error, so I thought it might be a regression in flask-migrate.

@miguelgrinberg
Copy link
Owner

I think you have a misunderstanding related to how Alembic works. When you run flask db migrate Alembic compares the current state of the database with the current state of your models, and generates a migration script with the differences.

So when you do this:

> pip install flask-migrate==2.6.0
> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade xxx -> yyy
> rm migrations/yyy.py
> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
# NO ERROR RETURNED HERE

The fact that you deleted a migration does not change anything. Your models and your database are still matching so there is nothing to do and for that reason Alembic just returns without doing anything. You will definitely have issues when you try to migrate the database again, because that migration script that you deleted introduced an inconsistency in your migration repository.

@ghost
Copy link

ghost commented Feb 11, 2021

I'm definitely not expecting for the operation to be successful. I'm just expecting for an error message to be displayed. The cause of the issue seems to be this commit: 4887bd5

flask-migrate doesn't use the root logger anymore, so alembic.ini needs to be updated to include configuration for flask_migrate logger.

@miguelgrinberg
Copy link
Owner

Okay, you should have started by explaining the problem, I do understand now. This is now fixed in the master branch.

@josipbudzaki
Copy link

Thanks for the update, that helped me to track down my problem as well!

@Victor7095
Copy link
Author

Victor7095 commented Feb 16, 2021

Sorry, I couldn't create an example code for testing. But I think the problem(not showing error message) is related to the alembic_version table. I just tried doind that again and didn't received an error message. Some steps I tried today.

  • The migrations/versions folder had 5 registered migrations.
  • I deleted the migrations folder but didn't deleted database and alembic_version table still had the last migration id.
  • I ran flask db init and it created the migrations folder.
  • Running flask db migrate doesn't show any error message.
    BUT, if I delete alembic_version table and run flask db migrate it shows: No changes in schema detected.

So, I guess I caused that just by messing with the migrations folder.

@Virendra1485
Copy link

You just need to import models in the init.py file of package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants