Hi all -
I have a posts page that I’m trying to access but I keep getting this prisma error.
api | Error:
api | Invalid `prisma.post.findMany()` invocation:
api | error: Environment variable not found: DATABASE_URL.
api | --> schema.prisma:5
api | |
api | 4 | provider = "sqlite"
api | 5 | url = env("DATABASE_URL")
api | |
api | Validation Error Count: 1
Any ideas how I might resolve this?
On the command line try
Yarn rw studio
This should open prisma studio , can you confirm the table has been created there ?
If it doesn’t you should change the URL to ‘file:/.dev.db’
Prisma will look for dev.dB and it not found would create 1 for you
It looks like I get an error when I run
Yarn rw studio
Here’s a video clip of what I see when I click “posts” in the UI. You’ll see that the screen quickly flashes to the default rw generated page, but then throws the error.
Apologies , the command is “yarn rw db studio”.
The error says
error: Environment variable not found: DATABASE_URL.
So, that’s where I’d start. Let’s find
DATABASE_URL in your envs and make sure it points to your sqlite db.
I’m curious how
db save and
db up were able to apply the migrations, though, for your Posts model.
Can you confirm as @asdethprime noted:
- you are using sqlite
- you do have .db sql file in your folders and at the path location of your DATABASE_URL env
- what your
DATABASE_URL env value is
- in which .env
DATABASE_URL is set (defaults,. example or just .env)
See: https://redwoodjs.com/docs/environment-variables for more info on environment variables
dev.db file should be in
api there are two directories:
db contains the plumbing for the database:
… snip …
After we add our first database table there will also be a SQLite database file named
dev.db and a directory called
migrations created for us.
migrations contains the files that act as snapshots of the database schema changing over time.
DATABASE_URL is not commented out in the envs.
@dthyresson Thanks. I didn’t have a .env.defaults file. I thought that it was typically automatically added, but maybe I missed something, or skipped a step. Adding that file and then running
yarn rw db up appears to have fixed my issue. Thanks for the help.
Your frontend for the app looks really good ; could you perhaps share the GitHub repo ; keen to see your frontend code.