Tutorial.Cells: "Failed to validate the query"

I wanted to test RedwoodJS by doing the tutorials. Everything worked fine until I reached the Cells section. I followed and didn’t customize anything.

Right after creating my first cell and integrateding it into HomePage.js I don’t have the same output as mentioned in the screenshot. I get an error in the terminal:

Invalid `db.post.findMany()` invocation in
api | /Users/me/Documents/dev/git/redwoodblog/api/src/services/posts/posts.js:4:18
api |
api |   1 import { db } from 'src/lib/db'
api |   2
api |   3 export const posts = () => {
api | → 4   return db.post.findMany(
api |   Failed to validate the query: `Field does not exist on enclosing type.` at `Query.findManyPost`

The result on the page:
Bildschirmfoto 2022-02-13 um 15.02.41

How to solve that error?

Hi Giregar! Sorry about this…could you try stopping and re-starting the dev server? If that doesn’t help, try stopping the server, then running:

yarn rw prisma generate

And then starting the dev server again. We normally do this behind the scenes automatically, but this seems like the kind of error that would happen if that had NOT run like it should. Let me know if it works!

1 Like

Thank you for the fast response rob. The error changed to

api | Invalid `db.post.findMany()` invocation in
api | /Users/me/Documents/dev/git/redwoodblog/api/src/services/posts/posts.js:4:18
api |
api |   1 import { db } from 'src/lib/db'
api |   2
api |   3 export const posts = () => {
api | → 4   return db.post.findMany(
api |   The table `main.Post` does not exist in the current database.

Did you run the migration to create the table in the database?

yarn rw prisma migrate dev

There should have been a step to do that after adding Post to the schema.prisma file, but before creating the cell.

1 Like

Yes I did run the migration and can see the table in Prisma Studio. The output after running yarn rw prisma migrate dev is

Environment variables loaded from .env
Prisma schema loaded from api/db/schema.prisma
Datasource "db": SQLite database "dev.db" at "file:./dev.db"

Already in sync, no schema change or pending migration was found.

I don’t know what I could have done differently than in the tutorial, but I assume that I followed the steps 1:1. So I will just delete the project again and start the whole tutorial from scratch. Thank you for your help! :slight_smile:

Okay, I did the tutorial 1:1 again and I noticed, that the error already occurs when creating a post editor.

I can connect to Prisma.

When I try to save a new post, I get the following error:

api | Invalid `db.post.create()` invocation in
api | /Users/me/Documents/git/redwoodblog/api/src/services/posts/posts.js:14:18
api |
api |   11 }
api |   12
api |   13 export const createPost = ({ input }) => {
api | → 14   return db.post.create(
api |   Failed to validate the query: `Field does not exist on enclosing type.` at `Mutation.createOnePost`

At that step, I didn’t touch any of the auto-generated files.

Problem solved! The issue was Node 16. Now I switched to Node 14 and everything works just fine.

Please excuse me, I’m curious, I’m also running Node v16 (v16.11.1 to be precise) I went all the way through Tutorial 1 without this error so I don’t think it is Node that is your problem. I’m also too new to Redwood to be of more help though.

I did the tutorial 3 times in total on two different machines. Switching from Node 16.13.2 to version 14.17 worked for me in the 3rd attempt.

1 Like

I’m having the same problem. I completed tutorial 1 just fine, but tutorial 2 keeps giving this:

The table main.Post does not exist in the current database.

Switching node from v16 to v14 did nothing for me.

@mattsears18 I know this sucks, but you could try deleting node_modules and then running yarn install again. It’s the nuclear option, but the last time this came up it looked like Prisma had two copies of its generated client libraries lying around and this was the surefire way to fix it.

@dthyresson did we ever learn anything more about this issue?

@rob thanks. I thought I tried that but I’ll give it another shot. The issue popped up after I created a .env, so that might be related… I’ll see if I can reproduce.

It seems like I have to yarn rw prisma regenerate everytime i come back to my project…

Heyooo everyone!

So sorry everyone is struggling with this issue! I’m liasing with the Prisma team to resolve this issue ASAP.

For now here’s the issue to track on our side: https://github.com/redwoodjs/redwood/issues/4605

Temporary fix if you keep facing the issue is to remove the prisma client generated at the wrong location

rm -rf api/node_modules/.prisma

This isssue has now been resolved on Prisma v3.11.1!

Thank you all for reporting :slight_smile: