我正在拔掉头发,任何帮助都将不胜感激。
我正在尝试在部署我的新应用时运行alembic升级。我已经搜索了3个小时的堆栈溢出,但没有找到任何有用的东西。我做的每一件事都有相同的结果。
这来自我的heroku发布日志FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section
我在我的ProcFile中使用以下代码
release: alembic upgrade head
worker: python bot.py我在我的env.py文件中使用了类似的东西
http://allan-simon.github.io/blog/posts/python-alembic-with-environment-variables/
但这是我实际的.已修改为不应尝试打开alembic.ini
from logging.config import fileConfig
from sqlalchemy import engine_from_config, create_engine
from sqlalchemy import pool
from alembic import context
import logging
logging.basicConfig()
logging.info("running upgrade with logging")
target_metadata = None
import sys
import os
sys.path.insert(0, os.getcwd())
from guildmate.persistence.database_objects import BASE
logging.info("got base")
target_metadata = BASE.metadata
import dotenv
dotenv.load_dotenv()
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
logging.info("running offline")
database_url = os.getenv("DATABASE_URL")
logging.info(f"{database_url}")
connectable = create_engine(database_url)
context.configure(
url=database_url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
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.
"""
logging.info("running offline")
database_url = os.getenv("DATABASE_URL")
logging.info(f"{database_url}")
connectable = create_engine(database_url)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata, compare_type=True
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()我正在使用环境变量来配置数据库的url -尽管它似乎从来没有到达那里。
升级在本地运行得很好,我可以日夜运行它。
我还没有想出从alembic获取任何形式的日志记录的方法,或者堆栈跟踪或任何东西,所以我甚至不知道是哪一行导致了问题。
我能想到的唯一一件事就是发布阶段使用的是预发布代码?它甚至没有任何alembic的东西,所以这是没有意义的。我真的不知道。
发布于 2020-09-04 09:27:07
太愚蠢了。即使我已经通过env.py完成了alembic.ini中的所有配置,它仍然必须有一个alembic.ini。我在没有url的情况下把一个放入我的repo中,它工作得很好。
https://stackoverflow.com/questions/63715036
复制相似问题