Prisma $queryRaw cannot grab any tables added from migration

Hey there, I have a web app I’ve been working on, on Redwood v0.31.0
I have a few tables such as ‘Tournaments’ and ‘User’, and everything works great with the general db operations via prisma.

Having said that, I have some calls I need to do that need raw sql access (such as checking number of relations and comparing that with a number in the record that indicates max relations allowed). However when I use queryRaw, it gives me this error:

Raw query failed. Code: 42P01. Message: relation "tournament" does not exist

Even when I select all from User, it gives me a single user account that I had when I first setup the project with redwood, but nothing since then (and again, I can see the multiple user accounts and tournaments with regular db access such as db.tournaments and db.users or even with prisma studio)

I feel as though somehow queryRaw is targeting the old database (potentially an SQL database I used when I setup redwood before moving to postgresql) but I’m unsure how to confirm this or how to fix this.

Any suggestions are appreciated!

Have you tried capital “Tournament” or “Tournaments”?

Models and tables are capitalized by default.

It can be useful to write abs test your query praise your app on TablePlus and the. Use that query in the raw statement.

Also if you turn query logging on you can see exactly what Prisma is doing: Docs - Logger : RedwoodJS Docs

Ah! Good idea with the testing of the queries, it looks like for some reason the tables are nested at ‘public.Tournament’ instead of just ‘Tournament’.

Thanks for your help!

EDIT: Actually, it seems also wrapping ‘Tournament’ in double quotes fixed the issue, so something like
‘SELECT id, “maxPlayers”, active FROM “Tournament”;’

Glad you got it working!

Yes, due to the capitalization and the camel casing of column names, quotes are needed.

I forgot to mention, but another place to see the underlying SQL is to inspect the migration sql files Prisma created during a “migrate dev”. That should show the table names.