DATABASE_URL var not found when deploying to Fly.io

I'm deploying my first OpenSaaS Wasp app, but I'm running into the following error during the deployment process: [ Db !] Error: P1012 [ Db !] [ Db !] error: Environment variable not found: DATABASE_URL. [ Db !] --> schema.prisma:4 [ Db !] | [ Db !] 3 | provider = "postgresql" [ Db !] 4 | url = env("DATABASE_URL") [ Db !] | The app still deploys, and I see my client, server, and database listings on Fly, but the app, of course, isn't functional. I've tried changing my DATABASE_URL in env.server, adding my postgres url as a secret in Fly manually, etc, and have messed around with it quite a bit to no avail. Maybe (hopefully) I'm just making a very basic newbie mistake, but has anyone else faced this issue?
7 Replies
kapa.ai
kapa.ai5mo ago
Hi @howcaniexplain. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This issue has been reported by other users as well, and it seems to be related to the way Prisma handles environment variables. The DATABASE_URL environment variable is set inside Docker for runtime, but the Prisma client is generated outside of Docker, which is likely why you're seeing this error message during the build process [source (https://github.com/wasp-lang/wasp/issues/1282)]. However, this error message might not be indicative of a real problem. As long as the DATABASE_URL is correctly set in the Fly.io environment, your app should be able to connect to the database at runtime. You can check your environment variables on Fly.io by running flyctl secrets list in your terminal [source (https://wasp-lang.dev/docs/advanced/deployment/manually#set-up-a-flyio-app)]. If you're still having trouble, make sure you've followed the steps for setting up a Fly.io app correctly. Specifically, when you run flyctl launch --remote-only, make sure to say yes to Would you like to set up a PostgreSQL database now?. Fly.io will then set a DATABASE_URL for you [source (https://wasp-lang.dev/docs/advanced/deployment/manually#set-up-a-flyio-app)]. If you've done all of this and are still experiencing issues, it might be worth reaching out to the Wasp community for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @howcaniexplain, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
howcaniexplain
howcaniexplainOP5mo ago
Tried to deploy with Railway instead, and the same issue persists. I'm using the Postgres DB provided by WASP. @kapa.ai How and where do I specify the DATABASE_URL if I'm using the built in database?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- If you're using the built-in database provided by Wasp, you can specify the DATABASE_URL in two ways: 1. Using the .env.server file: You can set the DATABASE_URL environment variable by adding it to the .env.server file in the root directory of your Wasp project. If the file doesn't exist, you'll need to create it. The value of DATABASE_URL should be the connection string to your database [source (https://wasp-lang.dev/docs/data-model/backends#connecting-to-an-existing-database)]. 2. Inline when running wasp: You can also set the DATABASE_URL inline when running wasp. This is useful for running a certain wasp command on a specific database. Here's an example:
DATABASE_URL=<my-db-url> wasp ...
DATABASE_URL=<my-db-url> wasp ...
Replace <my-db-url> with your actual database URL [source (https://wasp-lang.dev/docs/data-model/backends#connecting-to-an-existing-database)]. Remember, the DATABASE_URL should be in the following format: postgresql://mydbuser:mypass@localhost:5432/nameofmydb [source (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables)]. If you're deploying to a platform like Railway, you'll need to set the DATABASE_URL in the environment variables section of your Railway dashboard. This is similar to how you would set it on Fly.io or Heroku. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @howcaniexplain, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho5mo ago
You are seeing that error and your app is not working? How did you deploy to Fly? Using Wasp's CLI or manually? How did you deploy to Railway, what kind of command did you run? For Fly, I'd advise to go carefully through these docs: https://wasp-lang.dev/docs/advanced/deployment/cli For Railway, these docs: https://wasp-lang.dev/docs/advanced/deployment/manually
Deploying with the Wasp CLI | Wasp
Wasp CLI can deploy your full-stack application with only a single command.
Deploying Manually | Wasp
This document explains how to build and prepare your Wasp app for deployment.
martinsos
martinsos5mo ago
@howcaniexplain that is a spurious error that gets printed every time when running wasp build, meaning it is not an error at all but a false message, and it is removed in the newer version of Wasp, sorry about that! However you said your app is not working -> the cause however must be something else! How do you know it is not working? What does work? What do server logs say?
howcaniexplain
howcaniexplainOP5mo ago
The button to Log In was not appearing, and manually going to the login page and attempting to log in or create an account was resulting in an error. However, manually resetting some of my Fly secrets, then redeploying and restarting the server and client apps seemed to have fixed the issue. Thanks!
martinsos
martinsos5mo ago
Great! It was probably server failing due to fauly deploy / missing secrets. Glad you got it working!
Want results from more Discord servers?
Add your server