我想我Flask
項目,整合Alembic
我的應用程序結構看起來像蒸餾器:蒸餾器版本說導入錯誤
project/
configuration/
__init__.py
dev.py
test.py
core/
# all source code
db/
migrations/
__init__.py
alembic.ini
env.py
versions/
當我嘗試從我db
目錄下面,我看到
File "migration/env.py", line 55, in run_migrations_online
from configuration import app, db
ImportError: No module named configuration
我試着在Request a simple alembic working example for Auto Generating Migrations提到的解決方案,但它不爲我
工作我在env.py
run_migrations_online()
變革的方法是
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()
我怎樣才能解決這個問題?
跑了一個更好,更持久的解決方案,我第二什麼@Palasaty建議。只需更新你的'env.py'文件以使用正確的目錄。 – 2017-06-09 18:32:56