我尝试在 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 许可协议
You must
cd
to the directory that has thealembic.ini
to run thealembic
command, that is, thealembic.ini
must be found in the当前工作目录;或者您可以使用alembic -c path/to/alembic.ini
指定配置文件位置。而且你的 alembic ini 似乎坏了,你应该有
script_location
在那里,因此如果你的迁移在alembic
子目录中,alembic.ini
喜欢:目录布局 必须 这样,如果你的
script_location = alembic
这意味着你有: