FAILED: configuration file 'alembic.ini' not found

I tried to change in Alembic, but when I try to start Alembic current, I got an error. I am new to alembic, please tell me why I get this error and how to solve it?

I can see alembic.ini in the migration folder, as well as the revision IDs used by Alembic, and everything seems fine.

 $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 ### 
+7
python alembic
source share
2 answers

You must cd into the directory with alembic.ini to run the alembic , that is, alembic.ini should be found in the current working directory; or you can specify the location of the configuration file using alembic -c path/to/alembic.ini .

And it seems that your alembic ini is broken, you should have script_location there, so if your migrations are in the alembic subdirectory, alembic.ini should read something like:

 [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 

The layout of the directory should be such that if your script_location = alembic means you have:

 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 
+3
source share

To deploy the script, follow these steps:

ssh ... alembic upgrade head

Antii's answer gives a direct answer, which is the -c option:

ssh ... alembic -c /path/to/alembic.ini upgrade head

However, then you can get like me:

FAILED: Path doesn't exist: 'alembic'. Please use the 'init' command to create a new scripts folder.

Alembic cannot interpret your script_location intent in alembic.ini . Usually you run alembic from a directory using alembic.ini , and alembic can interpret your script_location as a relative path.

However, when you run it with a simple script deployment or otherwise from another directory, it does not know where to look, and it does not use the alembic.ini directory to guess the location (it seems to me that Antii suggested?).

If you look in the alembic source code here , you will see that alembic wants either 1) an absolute path, 2) a package path, or 3) a relative path from the working directory (default case).

Therefore the second level of this answer

Option 1: Absolute Path

(I have not tested this!) Specify the absolute path to the alembic directory in alembic.ini . This does not work for me because the code becomes unsportsmanlike:

 ... script_location = /path/to/alembic/ ... 

Option 2: package path

Specify the package path in alembic.ini :

 ... script_location = rootpackage:alembic # or maybe rootpacakge.xyz:alembic ... 

and of course, it should actually be a package, so the place with alembic.ini should have __init__.py .

Option 3: Relative Path

Instead of starting the alembic update directly in your deployment script, make a bash script to cd in the right directory, and then run it.

0
source share

All Articles