You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from myapp.models import Base
target_metadata = Base.metadata
and a local virtual environment. If I run from ., I can import the app:
$ .venv/bin/python
Python 3.8.3 (default, May 23 2020, 16:34:37)
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from myapp import models
>>>
however running alembic seems to not honor this:
$ .venv/bin/alembic revision -m "rev1" --autogenerate
Traceback (most recent call last):
File ".venv/bin/alembic", line 8, in <module>
sys.exit(main())
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/config.py", line 559, in main
CommandLine(prog=prog).main(argv=argv)
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/config.py", line 553, in main
self.run_cmd(cfg, options)
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/config.py", line 530, in run_cmd
fn(
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/command.py", line 212, in revision
script_directory.run_env()
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/script/base.py", line 481, in run_env
util.load_python_file(self.dir, "env.py")
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
module = load_module_py(module_id, path)
File "/home/classic/dev/test/.venv/lib/python3.8/site-packages/alembic/util/compat.py", line 182, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "alembic/env.py", line 20, in <module>
from myapp.models import Base
ModuleNotFoundError: No module named 'myapp'
that seems pretty unnecessary so let's fix that.
The text was updated successfully, but these errors were encountered:
so, I'm going to append the path at the end, and hopefully this doesnt cause any issues. I have a feeling there may have been some concerns with this in the past, but I can't remember what they are. So let's put it out and then if there's a problem, then we'll know, and we can change this behavior to be a config file thing. But I think this should work the way it is because we normally load env.py relative to the current path with the default alembic.ini config that has a relative path.
Just speculating about possible past concerns of adding "." to sys.path:
There may be a conflict between the installed alembic package and the ./alembic/ folder ("python package") when alembic was initialized with alembic init alembic as described in the docs. It may at least cause some confusion.
I know there is no ./alembic/__init__.py file so technically ./alembic/ wouldn't be a python package. However, maybe the __init__.py file needs to be added in order to fix this issue?
Maybe it would be more advisable to initialize alembic with another folder name, say alembic init migrations? Should that be reflected in the docs?
given a structure:
with env.py:
and a local virtual environment. If I run from ., I can import the app:
however running alembic seems to not honor this:
that seems pretty unnecessary so let's fix that.
The text was updated successfully, but these errors were encountered: