引发KeyError(key)KeyError:'formatters'

时间:2018-11-29 16:13:45

标签: python logging alembic

我正在创建一个简单的Flask API。我正在使用Alembic进行数据库迁移(Postgres)。我的alembic.ini文件出现以下错误。

    Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    manager.run()
  File "/Users/omorgan/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/flask_script/__init__.py", line 417, i
n run
    result = self.handle(argv[0], argv[1:])
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/flask_script/__init__.py", line 386, i
n handle
    res = handle(*args, **config)
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/flask_migrate/__init__.py", line 95, in wrapped
    f(*args, **kwargs)
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/flask_migrate/__init__.py", line 215,in migrate
    version_path=version_path, rev_id=rev_id)
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/alembic/command.py", line 176, in revision
    script_directory.run_env()
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/alembic/script/base.py", line 427, inrun_env
    util.load_python_file(self.dir, 'env.py')
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/alembic/util/pyfiles.py", line 81, inload_python_file
    module = load_module_py(module_id, path)
  File "/Users/admin/.local/share/virtualenvs/cp-api-CkIfmfOt/lib/python3.6/site-packages/alembic/util/compat.py", line 82, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "migrations/env.py", line 12, in <module>
    fileConfig(config.config_file_name)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/config.py", line 76, in fileConfig
    formatters = _create_formatters(cp)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/config.py", line 109, in _create_formatters
    flist = cp["formatters"]["keys"]
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/configparser.py", line 959, in __getitem__
    raise KeyError(key)
KeyError: 'formatters'

我的环境: Python 3.6.5 Pipenv Mac OSX Mojave

我的Alembic文件如下:

# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = alembic

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# timezone to use when rendering the date
# within the migration file as well as the filename.
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; this defaults
# to alembic/versions.  When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat alembic/versions

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = postgres://crowdplan:cr0wdpl@n@localhost:5432/crowdplan


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

我已经四处搜索,似乎字典中缺少该值,但是,它正按照文件中列出的方式传递给解释器。该文件在初始化时由alembic自动生成。

如果有人能指出我正确的方向,那将不胜感激。

谢谢

0 个答案:

没有答案