Unable to Create or See Tables in Railway Postgres from Deployed Backend

johnthomaswalden
FREE

3 months ago

We have a FastAPI backend deployed on Railway and a Postgres database provisioned via Railway. Our backend uses the DATABASE_URL provided by Railway (e.g., postgresql://postgres:...@postgres.railway.internal:5432/railway). On startup, our backend runs code to create tables using both SQLAlchemy’s Base.metadata.create_all() and a raw SQL CREATE TABLE IF NOT EXISTS runs (...) statement.

Symptoms:

  • The backend logs show that the table creation code runs successfully (e.g., “Runs table created (if it did not already exist).” and “Tables created on startup!”).

  • However, when the backend tries to insert into the runs table, we get the error:

psycopg2.errors.UndefinedTable: relation "runs" does not exist

  • When we check the Railway Postgres Data UI, it says “You have no tables.”

  • We are certain the backend is using the correct DATABASE_URL (confirmed by printing it in logs).

  • We do not see any errors during table creation in the logs.

What we’ve tried:

  • Verified the DATABASE_URL in both the backend and Railway dashboard.

  • Attempted to create the table both via SQLAlchemy and raw SQL on backend startup.

  • Checked the Data UI for tables after deployment—still empty.

  • Looked for a public connection string to connect via a local SQL client, but only see the internal hostname.

Request:

  • Why are tables not being created or visible in the Railway Postgres Data UI, even though the backend logs indicate successful creation?

  • Is there a network isolation or schema issue that could cause this?

  • How can we reliably create and view tables in our Railway Postgres instance from our deployed backend?

Additional Info:

  • Project: [your Railway project name or ID]

  • Backend: FastAPI (Python)

  • Database: Railway Postgres

  • Example DATABASE_URL: postgresql://postgres:...@postgres.railway.internal:5432/railway

$10 Bounty

2 Replies

3 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 3 months ago


brij123987
FREE

3 months ago

Hey John,

You're likely running into a PostgreSQL schema mismatch or connecting to a different database/schema than the one shown in Railway's Data UI.

PostgreSQL uses schemas public to organize tables, and if the schema isn’t explicitly defined, your tables might be created in a different or temporary schema making them invisible in the Data UI.


brij123987
FREE

3 months ago

If you can paste a snippet of the code you're using to connect and create tables, I can provide a more precise solution.