Alembic / env.py target_metadata = metadata "No module name al_test.models"

When I use alembic to control the version of my project database, some of the codes in env.py are like:

# add your model MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from al_test.models import metadata

target_metadata = metadata

when I run 'alembic revision --autogenerate -m' Added user table '', I get an error: File "alembic / env.py", line 18, in the import metadata al_test.models ImportError: no module with named al_test.models

so how to resolve the issue? thank!

+5
source share
1 answer

It may be a little late, and you may have already figured out the problem, but I assume the problem is that your alembic / directory is not part of the system path. That is, you need to do something like:

import sys
sys.path.append(path/to/al_test)

from al_test.models import metadata
+3

All Articles