Forums

Problem with flask db migrate

I have a problem with flask and migrate. I changed my database model and now want to migrate that change.

Unfortunately, I get the following error message: https://pastebin.com/QCpqaNSg

It seems like this error has something to do with Python configparser.

I found the following stack exchange topic. There it is said it would be a bug in python’s configparser module.

https://stackoverflow.com/questions/52655708/configparser-py-keyerror-python-flask

Can somebody confirm that and tell me what to do about it? On my localhost the migration went fine.

I don't think that the answer there is correct. They're referring to "a bug in configparser pre 3.2". But configparser 3.2 was released in 2011, and Python 3.5 was released in 2015.

From the stack trace you pasted:

  File "migrations/env.py", line 13, in <module>
  File "/usr/lib/python3.5/logging/config.py", line 76, in fileConfig
    formatters = _create_formatters(cp)
  File "/usr/lib/python3.5/logging/config.py", line 109, in _create_formatters
    flist = cp["formatters"]["keys"]
  File "/usr/lib/python3.5/configparser.py", line 956, in __getitem__
    raise KeyError(key)
KeyError: 'formatters'

The problem seems to be that the Python logging module is trying to configure itself from a file, but it can't find a formatters section in the file. Do you have any explicit logging config in your code?

Not in my app, but the site-packages alembic and flask-migrate (which uses alembic) have to files with logging configs.: alembic.ini.mako.

Could it be, that this a python3.5 problem? On my local host I am using python3.7.

Perhaps it's a Python version issue, but I doubt it. It may be a version issue with the various libraries you're using. Check that they match between your machine and your PythonAnywhere environment.

pip freeze, shows the same versions on both machines. Except for typed-ast which is only installed on pythonanywher.

I will create a new venv on my machine with python3.5 to check if the conflict has something to do with the python version.

I found the problem: it was with the alembic package. For what ever reason the standard configuration wasn't present at my pythonanywhere-account. The strange thing is, that the standard configuration gets created with

flask db init

without it the database won't work.

As a solution I just uploaded the configuration from my local machine.

The topic is closed for me now.

OK -- glad you were able to work out a solution.