I'm running VS Code Python 3.12.8 in an Azure Function using Flash and venev. I installed SQLAlchemy to get my postgres SQL going, and I cannot get Alembic to do the first migration.
It errors and will not leave a trace, print or debug line. I only get a stack trace in terminal or out putted in a file log.
I can run this code just fine.. SO I know access, accounts and passwords are correct
from sqlalchemy import create_engine, text
DATABASE_URL = "postgresql://************************/postgres?sslmode=require"
engine = create_engine(DATABASE_URL, pool_pre_ping=True, echo=True)
try:
with engine.connect() as connection:
result = connection.execute(text("SELECT version();")) # ✅ Use `text()`
print("✅ Connected! PostgreSQL Version:", result.fetchone()[0])
except Exception as e:
print("❌ SQLAlchemy Connection Failed:", e)
In case it matters, here is my code layout
alembic.ini
# A generic, single-database configuration.
[alembic]
script_location = alembic
sqlalchemy.url = postgresql://%(PGUSER)s:%(PGPASSWORD)s@%(PGHOST)s:%(PGPORT)s/%(PGDATABASE)s?sslmode=require
# Logging settings
output_encoding = utf-8
[loggers]
keys = root, sqlalchemy, alembic
[handlers]
keys = console, file
[formatters]
keys = generic
[logger_root]
level = DEBUG
handlers = console, file
[logger_sqlalchemy]
level=DEBUG
handlers=console
qualname=sqlalchemy.engine
propagate=0
[logger_alembic]
level=DEBUG
handlers=console,file
qualname=alembic
propagate=0
[handler_console]
class=StreamHandler
args=(sys.stdout,)
level=DEBUG
formatter=generic
[handler_file]
class=FileHandler
args=('alembic_debug.log', 'w')
level=DEBUG
formatter=generic
[formatter_generic]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
env.py
import sys
import os
sys.path.insert(0, os.getcwd())
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import create_engine
from alembic import context
from models import Base
import psycopg2
# ---