From e4042c4b31267670e52a7d3f8154d9aaf5651ffa Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 6 Jan 2016 21:54:31 +0100 Subject: it seemms that alembic do not find the models --- src/migrations/env.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/migrations/env.py') diff --git a/src/migrations/env.py b/src/migrations/env.py index 70961ce2..355c8dd1 100644 --- a/src/migrations/env.py +++ b/src/migrations/env.py @@ -9,7 +9,7 @@ config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. -fileConfig(config.config_file_name) +fileConfig("./alembic.ini") # add your model's MetaData object here # for 'autogenerate' support @@ -19,6 +19,7 @@ from flask import current_app config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI')) target_metadata = current_app.extensions['migrate'].db.metadata + # other values from the config, defined by the needs of env.py, # can be acquired: # my_important_option = config.get_main_option("my_important_option") @@ -49,25 +50,21 @@ def run_migrations_online(): and associate a connection with the context. """ - engine = engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool) - - connection = engine.connect() - context.configure( - connection=connection, - target_metadata=target_metadata - ) - - try: + connectable = engine_from_config( + config.get_section(config.config_ini_section), + prefix='sqlalchemy.', + poolclass=pool.NullPool) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata + ) + with context.begin_transaction(): context.run_migrations() - finally: - connection.close() if context.is_offline_mode(): run_migrations_offline() else: run_migrations_online() - -- cgit