失败:找不到配置文件“alembic.ini”

新手上路,请多包涵

我尝试在 Alembic 中进行更改,但是当我尝试运行 Alembic current 时出现错误。我是 alembic 的新手,请告诉我为什么会出现此错误以及如何解决?

我可以在迁移文件夹中看到 alembic.ini 以及 Alembic 使用的修订标识符,一切看起来都很好。

 $alembic current
No handlers could be found for logger "alembic.util"
  FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section

20c921506336_.py :

 """empty message

Revision ID: 20c921506336
Revises: None
Create Date: 2015-01-30 16:28:38.981023

"""

# revision identifiers, used by Alembic.
revision = '20c921506336'
down_revision = None

from alembic import op
import sqlalchemy as sa

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=True),
    sa.Column('email', sa.String(length=50), nullable=True),
    sa.Column('age', sa.Integer(), nullable=True),
    sa.Column('bestfriend_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['bestfriend_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(u'ix_user_age', 'user', ['age'], unique=True)
    op.create_index(u'ix_user_email', 'user', ['email'], unique=True)
    op.create_index(u'ix_user_name', 'user', ['name'], unique=True)
    op.create_table('friends',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('friend_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['friend_id'], ['user.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    ### end Alembic commands ###

def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('friends')
    op.drop_index(u'ix_user_name', table_name='user')
    op.drop_index(u'ix_user_email', table_name='user')
    op.drop_index(u'ix_user_age', table_name='user')
    op.drop_table('user')
    ### end Alembic commands ###

原文由 Linda 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
1 个回答

You must cd to the directory that has the alembic.ini to run the alembic command, that is, the alembic.ini must be found in the当前工作目录;或者您可以使用 alembic -c path/to/alembic.ini 指定配置文件位置。

而且你的 alembic ini 似乎坏了,你应该有 script_location 在那里,因此如果你的迁移在 alembic 子目录中, alembic.ini 喜欢:

 [alembic]
script_location = alembic

# 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

目录布局 必须 这样,如果你的 script_location = alembic 这意味着你有:

 alembic.ini
alembic/   # this must match the script_location in alembic.ini
    env.py   # and this must be found at the script_location
    script.py.mako
    versions/
        20c921506336_.py

原文由 Antti Haapala – Слава Україні 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏