Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade alembic error #102

Closed
mrk24251 opened this issue Aug 7, 2020 · 2 comments
Closed

upgrade alembic error #102

mrk24251 opened this issue Aug 7, 2020 · 2 comments

Comments

@mrk24251
Copy link

mrk24251 commented Aug 7, 2020

When running:
alembic upgrade head
in my ubuntu console.

I got this error:
Traceback (most recent call last):
File "/usr/bin/alembic", line 11, in
load_entry_point('alembic==1.1.0.dev0', 'console_scripts', 'alembic')()
File "/usr/lib/python3/dist-packages/alembic/config.py", line 540, in main
CommandLine(prog=prog).main(argv=argv)
File "/usr/lib/python3/dist-packages/alembic/config.py", line 534, in main
self.run_cmd(cfg, options)
File "/usr/lib/python3/dist-packages/alembic/config.py", line 511, in run_cmd
fn(
File "/usr/lib/python3/dist-packages/alembic/command.py", line 279, in upgrade
script.run_env()
File "/usr/lib/python3/dist-packages/alembic/script/base.py", line 475, in run_env
util.load_python_file(self.dir, "env.py")
File "/usr/lib/python3/dist-packages/alembic/util/pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
File "/usr/lib/python3/dist-packages/alembic/util/compat.py", line 174, in load_module_py
spec.loader.exec_module(module)
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "app/alembic/env.py", line 8, in
from app.db.models import Base
ModuleNotFoundError: No module named 'app'

I don't change my Dockerfile.

My docker file is:

FROM python:3.8

RUN mkdir app
WORKDIR app/

RUN apt update &&
apt install -y postgresql-client

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

@Buuntu
Copy link
Owner

Buuntu commented Aug 11, 2020

You need to run it inside of the Docker image, where alembic and your project dependencies are installed. From the project README:

docker-compose run --rm backend alembic upgrade head

This will run alembic upgrade head from inside your backend container. You can also connect to the container directly and run any bash command by running:

docker-compose exec backend bash

That should open up an interactive bash prompt.

@Buuntu Buuntu closed this as completed Aug 11, 2020
@karolzlot
Copy link

karolzlot commented Jul 28, 2021

It is possible to run without docker, but you need to set vscode / pycharm to run python with PYTHONPATH=.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants