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

Chapter 4: Issues when using 'flask db migrate' #396

Open
gbmerrall opened this issue Jul 16, 2024 · 1 comment
Open

Chapter 4: Issues when using 'flask db migrate' #396

gbmerrall opened this issue Jul 16, 2024 · 1 comment
Labels

Comments

@gbmerrall
Copy link

Two issues occur when running 'flask db migrate'

  1. using -m flag causes a runtime error in alembic

$ flask db migrate -m "users table"
usage: alembic [-h] [--version] [-c CONFIG] [-n NAME] [-x X] [--raiseerr] [-q] {branches,check,current,downgrade,edit,ensure_version,heads,history,init,list_templates,merge,revision,show,stamp,upgrade} ...
alembic: error: argument {branches,check,current,downgrade,edit,ensure_version,heads,history,init,list_templates,merge,revision,show,stamp,upgrade}: invalid choice: 'users table' (choose from 'branches', 'check', 'current', 'downgrade', 'edit', 'ensure_version', 'heads', 'history', 'init', 'list_templates', 'merge', 'revision', 'show', 'stamp', 'upgrade')

  1. If I remove the -m flag I get an module not found error

$ flask db migrate

Traceback (most recent call last):
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/bin/alembic", line 8, in
sys.exit(main())
^^^^^^
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/config.py", line 636, in main
CommandLine(prog=prog).main(argv=argv)
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/config.py", line 626, in main
self.run_cmd(cfg, options)
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/config.py", line 603, in run_cmd
fn(
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/command.py", line 406, in upgrade
script.run_env()
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/script/base.py", line 582, in run_env
util.load_python_file(self.dir, "env.py")
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
module = load_module_py(module_id, path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/johndoe/.local/share/virtualenvs/microblog-IrJMmESS/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
spec.loader.exec_module(module) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 995, in exec_module
File "", line 488, in _call_with_frames_removed
File "/Users/johndoe/Code/microblog/db/env.py", line 7, in
from app import create_app
ModuleNotFoundError: No module named 'app'

I discovered this when adapting the tutorial to my own situation so to confirm if it was me or not, I checked out tag 0.3 from the github repo and followed Chapter 4 up to running ''flask db migrate;

It's also worth pointing out that 'flask db init' also provides different output from the tutorial.

$ flask db init
alembic.ini was created in the root of your project
db/ was created with your Alembic configs, versions/ directory and seeds.py

Versions of things

  • Python 3.12
  • alembic==1.13.2
  • flask-db==0.4.1
  • flask-migrate==4.0.7

These are slightly different to what's in requirements.txt in the repo. I can't compare versions for flask-db as it's not listed there.

@miguelgrinberg
Copy link
Owner

I don't know what "flask-db" is. This tutorial does not use that package. Please uninstall it, as it is probably interfering with flask-migrate.

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

No branches or pull requests

2 participants