Skip to content

Why Alembic does not detect models without importing them? #1693

Discussion options

You must be logged in to vote

Hi,

That's just how python works, it evaluates modules lazily, the first time you access them.
An usual solution to ensure that all models are import is to make use of a module file that imports all models in a single place, so you can import it and you are fine. __init__ is usually used for this.

In you case you could add inside the models package and __init__.py file that has something like

from .base import metadata

from .users import User
...

so in alembic env you can then just add from models import metadata

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@albertalexandrov
Comment options

Answer selected by albertalexandrov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants