Render Blueprint Deploy Fails: psycopg2 OperationalError during alembic pre-deploy migration (database does not exist)
First Render Blueprint deploy of a Docker web service fails in the pre-deploy migration (preDeployCommand running alembic) with psycopg2.OperationalError: connection to server at "dpg-...-a" (10.x.x.x), port 5432 failed: FATAL: database "yapdb" does not exist, even though render.yaml declares databases: - name: yap-db, databaseName: yapdb and wires DATABASE_URL via fromDatabase: {name: yap-db, property: connectionString}. The database instance shows as available, and the background worker using the same env starts, then logs the same error. Separately, custom domains on the new web service stay unverified even though DNS was set up ahead of time with CNAMEs to <service-name>.onrender.com.
Render treats databaseName (and service names) as requests, not guarantees: it appended a random suffix, creating database yapdb_p5cx with user yapdb_p5cx_user. The spec does say this ("Optional (Render may add a suffix)", https://render.com/docs/blueprint-spec). The connectionString Render injects has the right, suffixed path. The app broke because its config had a separate db_name = "yapdb" setting that overwrote the URL's path (a common pattern for per-run test databases).
Fix: never hardcode the database name in prod config; take it from the injected URL. Drop or empty any db_name override for prod, keep it only for test envs. Check the real name first:
curl -s -H "Authorization: Bearer $RENDER_API_KEY" https://api.render.com/v1/postgres/<dpg-id> | jq '{databaseName, databaseUser}'The services got suffixes too: yap-web became yap-web-cskm.onrender.com and yap-api became yap-api-0qes.onrender.com, because bare *.onrender.com names are global. DNS records created before the first deploy that point at yap-web.onrender.com point at a name that isn't yours. Subdomains (www, api) stay unverified. The apex can still verify, because CNAME flattening resolves it to Render's shared IPs. Fetch serviceDetails.url from GET /v1/services after the Blueprint sync, then update the CNAMEs.
Log tip: use render logs -r <srv-id> --start <deploy createdAt> --end <finishedAt> --direction forward -o text --confirm and grep for FATAL. The pre-deploy output is mixed in with the service logs, and a startup config dump can push the error out of the default tail.