本文介绍了Alembic:alembic版本说导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将
我做了 export PYTHONPATH =< path_to_project> 再次运行该命令,并成功运行
I am trying to integrate my Flask project with Alembic
My application structure looks like
project/ configuration/ __init__.py dev.py test.py core/ # all source code db/ migrations/ __init__.py alembic.ini env.py versions/
When I try to run the following from my db directory, I see
File "migration/env.py", line 55, in run_migrations_online from configuration import app, db ImportError: No module named configuration
I tried the solution mentioned in Request a simple alembic working example for Auto Generating Migrations, but it does not work for me
My method in env.py run_migrations_online() with change is
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ import os import sys sys.path.append(os.getcwd()) from configuration import app, db alembic_config = config.get_section(config.config_ini_section) alembic_config['sqlalchemy.url'] = app.config['SQLALCHEMY_DATABASE_URI'] target_metadata = db.metadata engine = engine_from_config( alembic_config, prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() if context.is_offline_mode(): run_migrations_offline() else: run_migrations_online()
How can I fix this?
解决方案
I did export PYTHONPATH=<path_to_project> and ran the command again and it ran successfully
这篇关于Alembic:alembic版本说导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!