Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

alembic

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

# add your model's 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 from al_test.models import metadata ImportError: No module named al_test.models

so how to solve the question? thanks!

like image 605
jiank Avatar asked Apr 18 '13 07:04

jiank


2 Answers

This might be a bit late, and you may have already figured out the issue, but my guess the problem is that your alembic/ directory is not part of the system path. I.e. you need to do something like:

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

from al_test.models import metadata
like image 75
prschmid Avatar answered Nov 13 '22 06:11

prschmid


Update your env.py like this, to add the current working directory to the sys.path that Python uses when searching for modules:

import os
import sys
sys.path.append(os.getcwd())

from al_test.models import metadata
target_metadata = metadata
....
....
like image 30
d_- Avatar answered Nov 13 '22 06:11

d_-