prisma: The table `(not available)` does not exist in the current database

Bug description

I’m getting this error with a PlanetScale database

Message: Error in Prisma Client request: 

{"type":"PrismaClientKnownRequestError","code":"P2021","message":"\nInvalid `prisma.counters.findMany()` invocation:\n\n\n  The table `(not available)` does not exist in the current database.","stack":"Error: \nInvalid `prisma.counters.findMany()` invocation:\n\n\n  The table `(not available)` does not exist in the current database.\n    at cb (/var/task/node_modules/@prisma/client/runtime/index.js:38683:17)\n    at async /var/task/node_modules/@prisma/studio-pcw/dist/index.js:391:34\n    at async /var/task/node_modules/@prisma/studio-pcw/dist/index.js:375:28\n    at async eval (eval at request (/var/task/node_modules/@prisma/studio-pcw/dist/index.js:408:52), <anonymous>:3:8)\n    at async $25632e7ad2eabd1d$var$PCW.request (/var/task/node_modules/@prisma/studio-pcw/dist/index.js:408:46)\n    at async /var/task/.next/server/pages/api/databrowser.js:767:28\n    at async /var/task/.next/server/pages/api/databrowser.js:759:41\n    at async /var/task/.next/server/pages/api/graphql.js:10924:7\n    at async /var/task/.next/server/pages/api/graphql.js:10924:7\n    at async handlerTraceWrapperSpan (/var/task/.next/server/pages/api/graphql.js:11268:22)"}
  
Query:
prisma.counters.findMany({
  take: 100,
  skip: 0,
  select: {
    slug: true,
    views: true,
    likes: true,
    loves: true,
    awards: true,
    bookmarks: true,
  }
})

How to reproduce

I’m not sure, but I have this setup in my repo jahirfiquitiva/jahir.dev@dev

Expected behavior

No response

Prisma information

Environment & setup

  • OS: macOS
  • Database: PlanetScale MySQL
  • Node.js version: 14.17.4

Prisma Version

3.6.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Tables usually have to exist first before you can use them via Prisma. You can use npx prisma db push for PlanetScale for example on a new branch, then merge that via a deploy request into your production branch.

Odd, I have the same issue!

Local and test environment (on Vercel) are connected to the same DB. Local works fine, test environment gives an error all the time. Redeploy does not fix it.

Somehow doing another npx prisma db push fixed it in my situation.

So, whenever we update schema.prisma file, we need to either use db-push (for testing) or prisma-migrate (for prod) to sync prisma schema with our database schema.

Hi, I encountered the same issue with Prisma/NextJS and PlanetScale.

No matter how many deployments I did through commits, I had a Prisma column (not available) error. My deployment wouldn’t work and yet my local version would run perfectly (same db, npx prisma db pull/push/generate…). Tried to build without the cache on Vercel, but nothing.

Eventually I fixed the issue by installing the Vercel CLI and using vercel --prod --force

Using Planetscale, this message will show when you havent merge to main branch, all I have to do is merge the current branch to main branch

I have the same(or maybe the same) issue: Description: code: 'P2021" ClientVersion: “4.6.1” meta: {table: ‘(not available)’}

I am using ubuntu and Postgresql in local env, I checked with prisma studio that ProductBody and Product tables exist


model Product {
  id String @id @default(cuid())
  body ProductBody?
}

model ProductBody {
  product   Product @relation(fields: [productID], references: [id])
  productID String  @id

  innerHTML String
}

when I remove bellow lines from orderBy, it works. maybe I cant use _relevance for inner relations 🤔

{
  body: {
    _relevance: {
	fields: ["innerHTML"],
	search: searchQuery,
	sort: "desc",
    }
  }
}

Note: above object gets used in orderBy of Product model which has relation with ProductBody model with prop innerHTML Example:

prisma.myModel.findMany({
  select:{
     products:{
       where:{/* filtering */},
       orderBy:[
        /* some order filters */
    
         // this works fine
         {
         _relevance: {
            fields: ["shortDescription"],
            search: searchQuery,
            sort: "desc",
           }
         },

        // this works fine too
        {
	   body: {
              innerHTML: "desc"
	   }
        },
      
         // this one causes the error
         {
           body: {
            _relevance: {
	        fields: ["innerHTML"],
	        search: searchQuery,
	        sort: "desc",
             }
           }
         }
    
       ],
    
      select: {}
     } // end of products
  }
})

For me, the problem was that Vercel was deploying my app using stale cache. I did a manual redeploy from Vercel’s website and it worked, just make sure to not check the cache checkbox.

stop the application and run npm run dev again if you are facing this locally. You may have got the boilerplate and changed from sqllite to mysql while the app was running. You will have to kill the app and reload npm run dev

Solved it by simply restarting prisma studio

Prisma Data Platform (Cloud) would run the exact same queries as your local application. Prisma Client (which is also used in the Data Platform) expects the database tables to exist already when you run a query against them.