我試圖在Heroku上運行一個相當簡單的Flask + SQLAlchemy站點,但我不確定應該如何運行我的遷移來設置我的數據庫。當我運行heroku run alembic upgrade head
,我得到以下錯誤:我應該如何在Heroku上運行alembic遷移?
Running `alembic upgrade head` attached to terminal... up, run.1
Traceback (most recent call last):
File "/app/.heroku/venv/bin/alembic", line 12, in <module>
load_entry_point('alembic==0.4.0', 'console_scripts', 'alembic')()
File "/app/.heroku/venv/lib/python2.7/site-packages/alembic/config.py", line 255, in main
CommandLine(prog=prog).main(argv=argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/alembic/config.py", line 250, in main
self.run_cmd(cfg, options)
File "/app/.heroku/venv/lib/python2.7/site-packages/alembic/config.py", line 241, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File "/app/.heroku/venv/lib/python2.7/site-packages/alembic/command.py", line 124, in upgrade
script.run_env()
File "/app/.heroku/venv/lib/python2.7/site-packages/alembic/script.py", line 191, in run_env
util.load_python_file(self.dir, 'env.py')
File "/app/.heroku/venv/lib/python2.7/site-packages/alembic/util.py", line 185, in load_python_file
module = imp.load_source(module_id, path, open(path, 'rb'))
File "alembic/env.py", line 80, in <module>
run_migrations_online()
File "alembic/env.py", line 63, in run_migrations_online
poolclass=pool.NullPool)
File "/app/.heroku/venv/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 349, in engine_from_config
return create_engine(url, **opts)
File "/app/.heroku/venv/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 330, in create_engine
return strategy.create(*args, **kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 64, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/app/.heroku/venv/lib/python2.7/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 289, in dbapi
對我來說,這似乎表明它試圖加載sqlite的東西(這是默認的我在alembic.ini
),但我有我的env.py
以下在努力使其使用Heroku的PostgreSQL的連接:
cur_db_uri = config.get_section_option('alembic', 'sqlalchemy.url')
my_db_uri = app.config.get('SQLALCHEMY_DATABASE_URI', cur_db_uri)
config.set_section_option('alembic', 'sqlalchemy.url', my_db_uri)
其中app
是瓶實例。我正在使用Flask-SQLAlchemy在應用程序中幹掉我的數據庫使用情況,並使用Flask-Heroku確保我的所有Flask配置變量都從Heroku環境變量中正確拉出。
謝謝,謝謝,謝謝。 – wheaties
這不適合我,你能幫我一下,http://stackoverflow.com/questions/17501082/alembic-migrations-for-flask – GangstaGraham