Getting a Prisma Error

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 | 
api | 
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 | 
api | Validation Error Count: 1

Any ideas how I might resolve this?

Thanks,
Connor

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

Thanks @asdethprime.

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. ezgif.com-video-to-gif

Apologies , the command is “yarn rw db studio”.

Hi @CRR.

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: Environment Variables | RedwoodJS Docs for more info on environment variables

The SQLite dev.db file should be in api/db:

Within 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.

Make sure DATABASE_URL is not commented out in the envs.

1 Like

@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.

1 Like

Your frontend for the app looks really good ; could you perhaps share the GitHub repo ; keen to see your frontend code.