connecting a Postgres database to a django APP

I am deploying an app that looks for DATABASE_URL ENV var.
I attached the database to the APP per instructions.

in the docs this paragraph does not explain what to put in fly.toml so the app can see the internal IP.

Note that for the app to be able to attach to the database it must 
have private_network enabled in fly.toml. This enables it to look up
 .internal addresses like the database URL. See Using Fly DNS for
 further details.

please explain???

If you provisioned your Postgres via flyctl, this should be enabled by default. Are you hitting any errors when trying to connect?


yes, ERROR:

django.db.utils.OperationalError: could not translate host name “dpg-c6rudbpt9dsa0ehlcio0” to address: Name or service not known
#29 4.803

Error error building: executor failed running [/bin/sh -c SECRET_KEY=dummy DATABASE_URL=postgres://saleor:zTYLDuAFed1fkTjp1pyBL2TWBi7hDWBT@dpg-c6rudbpt9dsa0ehlcio0/saleor python3 migrate --no-input]: exit code: 1


The url structure should have the following format:

I attached the database to the APP per instructions.

Would you mind linking the instructions you were following?

Did you attach using our CLI? E.G. fly pg attach ... ?

flyctl postgres attach --app djsaleor --postgres-app pg-saleor
Running flyadmin database-list
? Database “djsaleor” already exists. Continue with the attachment process? Yes
Running flyadmin user-list
Running flyadmin user-create
Running flyadmin grant-access

Postgres cluster pg-saleor is now attached to djsaleor
The following secret was added to djsaleor:

MY BAD! I had that DATABASE_URL hardcoded in my Dockerfile.

Sorry, my fault.

It deployed now. Thanks for your quick response. This platform seems to ROCK!

@jyoost Haha, no problem at all! Glad you got it figured out!

@sanswork my app is deploying, but the only thing in the logs is:

2022-02-05T05:29:52.397 proxy[09b8d96d] vin [error] Health check status changed ‘passing’ => ‘critical’

how do I find out why it is failing when nothing shows up in the logs?

Hi @jyoost

I’ve caved & created a PR -

happy Saturday! :grinning:

flyctl launch
An existing fly.toml file was found for app summer-fire-7886
App is not running, deploy...
Deploying summer-fire-7886
==> Validating app configuration
--> Validating app configuration done
TCP 80/443 ⇢ 8000
Remote builder fly-builder-withered-forest-9872 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 95.8s (0/1)                                                                           
[+] Building 20.8s (5/5) FINISHED                                                                  
 => CACHED [internal] load remote build context                                               0.0s
 => CACHED copy /context /                                                                    0.0s
 => ERROR [internal] load metadata for                      5.4s
 => ERROR [internal] load metadata for                              5.4s
 => ERROR [internal] load metadata for                          10.4s
 > [internal] load metadata for
 > [internal] load metadata for
 > [internal] load metadata for
Error error building: failed to solve with frontend dockerfile.v0: failed to create LLB definition: no active session for n8t4am48u2nooppecotf8zznc: context deadline exceeded

I ran flyctl launch a couple of times and it finally deployed and ran. WTF?