-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Migrate detects changes in sqlite but not in Postgres #216
Comments
Are you using a schema other than the default in your Postgres database? Alembic does not look on custom schemas by default. |
I understand that "public" is the default schema, which is what I'm using. |
Update: I started using a normal, (not in-memory) sqlite database, and it worked just fine, leaving just the Postgres problem. I edited the example above to reflect this. |
Are you using a |
I tried |
Not sure what can be the problem. Using your example script above I do get a migration generated.
|
Hmm...I'm going to try and run this again using a different environment and a fresh database and see if that works. |
I found what was causing it to break: the I assume this is an issue with Alembic, so I'll report it there, because it would be nice if an error message popped up instead of the database inexplicably becoming unmigratable. |
Thank you for your help! |
I tried Alembic by itself (so no Flask-SQLAlchemy or Flask-Migrate) and I got the following. Do you know why this wouldn't pop up when using Flask-Migrate? INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [alembic.util.messaging] Can't locate revision identified by '334bbe02f85d'
FAILED: Can't locate revision identified by '334bbe02f85d' |
Yes, because Flask-Migrate configures alembic for you. Some defaults are different in Alembic, for example, it expects the alembic.ini file in the current directory. |
I found why: the default |
If anyone else runs into this problem, I'd suggest adding the except block to the try/finally statement on line 78 of try:
with context.begin_transaction():
context.run_migrations()
except Exception as exception:
logger.error(exception)
raise exception
finally:
connection.close() Now when I run INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [alembic.env] Target database is not up to date. @miguelgrinberg, is there any reason not to update the |
@kjohnsen that is a good change. I took the env.py file from the Alembic project long time ago and this is what that project did then, I haven't looked at how things look over there these days, your change looks good to me, but I should also review the current env.py from Alembic and bring any other updates as well. |
Awesome. Thanks again for the help! |
|
A change proposed by @kjohnsen from miguelgrinberg#216. You can read more starting with [this comment](miguelgrinberg#216 (comment)).
A change proposed by @kjohnsen from #216. You can read more starting with [this comment](#216 (comment)).
I updated the env.py files in this repo from the latest Alembic versions. Released as v2.4.0. Closing. |
I'm not sure what's going on. I've looked at issues #4, #50, and #94 to try and figure out why
flask db migrate
wasn't working, and I made sure the database was empty and that models were imported. I even inserted aTest
model class right above wheremigrate
is defined, andflask db migrate
simply wouldn't detect any changes no matter what schema or database change I did.However, I can confirm that Flask-SQLAlchemy, at least, is detecting models just fine, since using
flask shell
I candrop_all()
andcreate_all()
and confirm that the database is changed as expected.For some reason using a
sqlite
database instead of Postgres works (i.e., a script is generated).Another thing: is there always supposed to be a
No changes in schema detected
message when there are no changes? I haven't delved into the guts of Alembic to see exactly where it's failing, but I found thatcontext.run_migrations()
on line 80 of themigrations/env.py
file fails. I wonder whether it's supposed to simply fail, or generate an empty script and theNo changes
message.Here's a minimum working example:
When I run
flask db migrate
, I expect adding the tabletest
to be detected, since the DB is empty, but instead I get the following:user@COMPUTER:~/migrate-test$ flask db migrate INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL.
To reiterate, the
No changes in schema detected
message doesn't show up--it simply exits without a return code of 0.The text was updated successfully, but these errors were encountered: