I have a Django app running on the app platform. I want to switch over to use connection pooling.
my_db
.my_pool
.Additionally, you can use these same variable names to refer to your database connection pool (PostgreSQL only). To do so, use the syntax
${<database component name>.<connection pool name>.VARIABLE_NAME}
. For example, to create a bindable variable for a pool’s connection string, you can use${mydb.mypool.DATABASE_URL}
.
So now my (abbreviated) appspec now looks like:
databases:
- cluster_name: postgres
db_name: my_db
db_user: my_db
engine: PG
name: postgres
production: true
version: "13"
# ...
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: ${postgres.my_pool.DATABASE_URL}
This flat out doesn’t work. The error from the build is:
07:24] django.core.exceptions.ImproperlyConfigured: Set the {postgres.my_pool.DATABASE_URL}
Which would indicate that the environment variable hasn’t been set correctly. Why doesn’t this format work?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
I’m also having this issue. Has anyone had success resolving this?
Hi there,
I’ve tested this with the following app spec file and it seems to be working as expected:
When you attached the database to your app, did you also select the pool?
Also as a side note, database values are not available during build time but are available at runtime.
Best,
Bobby
To follow up, if I set two environment variables:
After deployment, echoing the two variables via the console confirms that
${postgres.my_pool.DATABASE_URL}
format doesn’t work:The variable isn’t being replaced, it’s just being set as the literal string
${postgres.my_pool.DATABASE_URL}
. In other words, variable binding isn’t working.