microblog icon indicating copy to clipboard operation
microblog copied to clipboard

Chapter 4: Issues when using 'flask db migrate'

Open gbmerrall opened this issue 1 year ago • 2 comments

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.

gbmerrall avatar Jul 16 '24 07:07 gbmerrall

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.

miguelgrinberg avatar Jul 16 '24 07:07 miguelgrinberg

I'd the same issue and uninstalling flask-db solves it!

danielxu1987 avatar May 01 '25 13:05 danielxu1987