Generated scaffold is causing an error on web page

Hello, I just started using redwood I am trying to go over the tutorial on Redwood.
Currently I can’t go past Chapter 2:section1(Creating a Post Editor), I am getting this error:

api | 00:57:10 🌲 incoming request POST xxx /graphql
api | 00:57:10 πŸ› Parsing request to extract GraphQL parameters
api | 00:57:10 πŸ› Processing GraphQL Parameters
api | 00:57:10 πŸ› graphql-server GraphQL execution started: FindPosts
api | 00:57:10 🌲 Starting a sqlite pool with 13 connections.
api | πŸ—’ Custom
api | {
api |   "prisma": {
api |     "clientVersion": "5.2.0"
api |   },
api |   "timestamp": "2023-09-14T04:57:10.404Z",
api |   "target": "quaint::pooled"
api | }
api | 00:57:10 🚨
api | Invalid `db.post.findMany()` invocation in
api | D:\GitHub\cs490-hw2\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 | Operation 'findMany' for model 'post' does not match any query.
api | πŸ—’ Custom
api | {
api |   "prisma": {
api |     "clientVersion": "5.2.0"
api |   },
api |   "timestamp": "2023-09-14T04:57:10.410Z",
api |   "target": "post.findMany"
api | }
api | 00:57:10 🌲 request completed 47ms
api | 00:57:10 🚨 graphql-server
api | Invalid `db.post.findMany()` invocation in
api | D:\GitHub\cs490-hw2\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 | Operation 'findMany' for model 'post' does not match any query.
api |
api | 🚨 GraphQLError Info
api |
api | {
api |   "path": [
api |     "posts"
api |   ],
api |   "locations": [
api |     {
api |       "line": 2,
api |       "column": 3
api |     }
api |   ],
api |   "extensions": {}
api | }
api |
api | πŸ₯ž Error Stack
api |
api | PrismaClientUnknownRequestError: 
api | Invalid `db.post.findMany()` invocation in
api | D:\GitHub\cs490-hw2\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 | Operation 'findMany' for model 'post' does not match any query.
api |     at vn.handleRequestError (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:123:6902)
api |     at vn.handleAndLogRequestError (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:123:6119)
api |     at vn.request (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:123:5839)
api |     at async l (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:128:9763)
api |     at async D:\GitHub\cs490-hw2\node_modules\@graphql-tools\executor\cjs\execution\promiseForObject.js:18:35
api |     at async Promise.all (index 0)
api |
api | 00:57:10 🚨
api | Invalid `db.post.findMany()` invocation in
api | D:\GitHub\cs490-hw2\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 | Operation 'findMany' for model 'post' does not match any query.
api |
api | 🚨 GraphQLError Info
api |
api | {
api |   "path": [
api |     "posts"
api |   ],
api |   "locations": [
api |     {
api |       "line": 2,
api |       "column": 3
api |     }
api |   ],
api |   "extensions": {}
api | }
api |
api | πŸ₯ž Error Stack
api |
api | PrismaClientUnknownRequestError: 
api | Invalid `db.post.findMany()` invocation in
api | D:\GitHub\cs490-hw2\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 | Operation 'findMany' for model 'post' does not match any query.
api |     at vn.handleRequestError (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:123:6902)
api |     at vn.handleAndLogRequestError (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:123:6119)
api |     at vn.request (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:123:5839)
api |     at async l (D:\GitHub\cs490-hw2\node_modules\@prisma\client\runtime\library.js:128:9763)
api |     at async D:\GitHub\cs490-hw2\node_modules\@graphql-tools\executor\cjs\execution\promiseForObject.js:18:35
api |     at async Promise.all (index 0)
api |
api | 00:57:10 πŸ› Processing GraphQL Parameters done.

This error happens when I try to access the generated scaffold through the local host website (http://localhost:8910/posts).
Currently I am using node version 18.17.1, yarn version 1.22.19, windows 10, and RW was created for javaScript.
I have tried to make the same calls in a linux VM and it worked, but for some reason it does not work on windows.
These are the calls that I have made to reproduce the error:

$ yarn create redwood-app /PATH
$ cd path
$ yarn rw dev
//inside vsCode make the changes to the schema file
$ yarn rw prisma migrate dev
$ yarn rw g scaffold post
//check the webpage
//error appears on terminal

schema file after changes:

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}
generator client {
  provider      = "prisma-client-js"
  binaryTargets = "native"
}
model Post {
  id        Int      @id @default(autoincrement())
  title     String
  body      String
  createdAt DateTime @default(now())
}

Web page:

That happened to me too but then I realized that this happens when you run the scaffold while the redwoodjs application is running on the localhost, so that the scaffold doesn’t break you have to run the scaffold without the redwoodjs application running.

Hey @Gui153 , welcome to our community,

To add a bit to @Parcero 's answer, the reason is though your code is updated, your prisma client - which is running with your RW application, doesn’t reflect those changes. Hence you have to stop/start the server.
It’s not necessary when your scaffolds do not concern the schema.

I’m facing the same error, also following the tutorial. Even after restarting the server I still get that error. Shall I remove all the scaffolded files and run the scaffold again or is there a simpler way ?

Without running the server you can run your scaffold by adding --force or -f at the end to overwrite your existing scaffold, I hope that helps you.

I tried with --force, but am still getting the same error.

As I understand, the api\src\services\posts\posts.ts file is trying to call db.post.findMany() which does not exists or is not found.

What is generating that db.post.findMany() function ? Is it determined from the schema ?

Be sure to migrate your database so that the db has the table and also the Prisma client is generated.

Hi @dthyresson,

Forcing scaffolding and re-doing the migration did fix it. Surprisingly the migration stated β€œAlready in sync, no schema changes or pending migration was found.”, but it fixed the issue.

I also noticed this only affects Windows. I did the exact same process on Ubuntu Linux yesterday, leaving the app running while scaffolding and on Linux it was working immediately.

Thanks for your help!