Django --> Postgres connection strings confirmation

I’ve created my first Fly app, with a local SQLite db and a production Postgres database. The app runs just fine locally, but now I’m trying to get the connection strings in place for Postgres and I’m not sure what goes where. I screenshotted my Django settings as well as the connection details given to me when I ran fly launch (all the details are blurred out).

The problem is that when I deploy the app I get an error indicating that the “database does not exist”. The required configuration block (top part) contains two fields which don’t have an explicit corollary in the connection strings (bottom part).

I’ve tried several combinations including commenting out the name field and putting Hostname into the Host field, putting Hostname into both Name and Host fields, and even copying the name from my Fly admin panel (ending in .fly.dev) but none of that works. I’m sure it’s an easy thing, but I can’t find the right combination. Could someone me in the right direction?

This is the error I’m getting:

OperationalError at /games
connection to server at "<name>.internal" (poiu:1:5d2f:a7b:ee:7c40:e823:1), port 5433 failed: FATAL:  database "<slightly different name>" does not exist

I haven’t used Django before, but please give this a try.

Given the Fly Postgres configuration below:

  • App Name: testtest123
  • Username: postgres
  • Password: passwordhere
  • Hostname: testtest123.internal
  • Flycast: fdaa:0:cf57:0:1::f
  • Proxy port: 5432
  • Postgres port: 5433
  • Connection string: postgres://postgres:passwordhere@testtest123.flycast:5432

Try this for the Django settings:

  • User: postgres
  • Password: passwordhere
  • Name: postgres (I think this is right, not 100% sure)
  • Host: testtest123.flycast
  • Port: 5432

Okay, it looks like it connected with the following.

DJANGO FIELD   FLY FIELD NAME
---------------------------------------------
USER           Username
NAME          'postgres'
PASSWORD       Password                      
HOST           Substring of "connection string", between the @ and the :
PORT           Proxy port                   

FWIW you can also try the simple dj_database_url library. It’s popular in the Django community, one of those simple libs we install early in just about every project.

Example:

# settings.py
import os
import dj_database_url

assert 'DATABASE_URL' in os.environ, "DATABASE_URL must be set in env!"

DATABASES['default'] = dj_database_url.parse(
    os.environ['DATABASE_URL'],
    conn_max_age=600,
    conn_health_checks=True,
)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.