question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alembic migrations don't work out of the box

See original GitHub issue

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

The documentation says “Because ORM is built on SQLAlchemy core, you can use Alembic to provide database migrations.”. However, running Alembic with the appropriate configuration (i.e., replacing the connection string with a non-async driver) produces empty migrations.

In order for Alembic to produce actual migrations, one can run MyModelName.build_table() on all of the tables you want to produce migrations for. I actually don’t know if this is the “correct” way to do this, but the docs have no information and I came up empty searching for the source code for any clues.

Diving through the source code, I noticed that the build_table method on Model was the only place metadata was being mutated (via the sqlalchemy.Table class constructor), so I tried calling this class method, and lo-and-behold, it worked!

To reproduce

I can provide a repo if needed, since this could be a few minutes of work.

Expected behavior

Alembic works out of the box with encode/orm.

Actual behavior

Alembic generates empty migrations.

Environment

  • OS: macOS 12.4 (21F79)
  • Python version: Python 3.10.5
  • ORM version: 0.3.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dlocommented, Aug 7, 2022

Just looked through, indeed you’re correct! Looks like this is unreleased code, though.

I didn’t think I’d need to test against master (instructions ask for repro on latest release and/or master–so apologies!)

0reactions
aminalaeecommented, Aug 7, 2022

No worries. Thanks for pointing this out. Feel free to add this to the docs and I will prepare the release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

alembic migration error flask - python - Stack Overflow
So my solution would be to do what it says and edit the migration file by hand and remove the lines you don't...
Read more >
Does alembic plan to add data migrations? #620 - GitHub
I understand that it is not an easy thing to add, but probably out-of-the-box way to run data migrations in "database reflection" mode?...
Read more >
Overview — Alembic 1.9.0 documentation
The module and class boxes do not list out all the operations provided by each unit; only a small set of representative elements...
Read more >
Database Migration Systems: An Overview
Although Alembic does not support repeatable migrations out of the box, there is a community contribution Alembic Utils that adds support ...
Read more >
Flask-DB Helps You Migrate, Seed and Reset Your ... - YouTube
It adds a new flask db command. For migrations it uses Alembic under the hood.Hit the subscribe button to receive more videos like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found