-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot update a table - code: 'P2021' #12256
Comments
seems similar to #10771 |
Seems the nested create fails here. Can you maybe enable query logging so we know what queries it tries to run? Can you please check if it works if you do not set |
Thanks! The problem is actually simpler than a nested create. I've simplified things: await db.user.update({
where: { id: uid },
data: {
avatar: uuid,
},
}); While the same query as raw sql succeeds: await db.$queryRaw(
Prisma.sql`UPDATE public.users SET avatar = ${uuid} WHERE id = ${uid}`
); |
Logs for failed query:
|
Logs for succeeding $queryRaw:
|
Thanks - I highly suspect this is a sideeffect of |
thanks as you suggest, I'm using this is in a postgres DB because I'm in the process of migrating to PlanetScale and I want to confirm things work before migrating |
I wonder if a quick note in the docs about this quick fix would be useful? |
No, this a) should not be happening and b) does not really make sense. The Client is now in the same state as before, right? That should behave the same. |
I agree! It's a bug for sure. For the record I did this and it solved the issue:
Then I undid the changes:
So maybe the bug is in the |
Can you still reproduce this in any way? |
I can't sorry, it fixed itself by doing the above. If it breaks again in the same way I'll let you know |
Okay so the same problem happened again: I activated logging and get this:
I can confirm that removing |
Can you please let us know where this database is hosted? Are you using something like Citus under the hood? |
ping @fergusmeiklejohn |
sorry! It's Supabase |
I wasn't able to reproduce this again. @fergusmeiklejohn are you seeing reoccurrence of this again? Just make sure you are on latest version of Prisma |
Sorry, I'm not using Prisma on the current project so can't check. |
I've faced the same issue today with PlanetScale and I saw that my database schema and all the records have been deleted. I don't know if Prisma did that but it was working completely fine last night. Luckily it was just a side project in development but if this is related to Prisma that's a major bug. Also in my case |
I don't think this issue describes deletion of a full schema and tables, but just an unfortunate error message that says What you describe would be a desaster for Prisma, but honestly Prisma Client itself does not even have any code that would drop a schema. The only command that can do this is Did you maybe create a new branch in Planetscale and then not merge that back to your main branch? That is a common oversight with the new and uncommon branching model of PlanetScale. |
I wanted to leave a comment here for others who might end up in this situation, as I found myself here today after everything was working just yesterday. I'm using PM2 to run my dev environment, and after looking over the notes here and trying a few things myself, I found that simply executing I do not have any logging or other indications as to why this happened. Hopefully this solution (as simple as it might be) works for others as well. |
I'm trying to do a relational upsert, as mentioned here: Mine isn't much different. Part of me wonders if this is related to mapping in the schema (tables or rows)? After removing the I was getting this error btw:
Now I'm getting a |
Create a new discussion please @ctsstc and share the information it is asking for. Thank you. |
Bug description
I cannot update a table in my postgres database with Prisma. I can read it, create but cannot update this particular table.
I can update this table with an SQL query. So I don't believe that the problem is the table or the schema. This seems to be a bug in Prisma.
How to reproduce
This prisma query fails with the above error:
This prisma query succeeds (provided I've already created this row):
Other queries on the user table succeed:
db.user.create
etcExpected behavior
I expect an update query to succeed. And if I does fail I expect an error message that can tell me why it has failed. This error message is telling me the table
'(not available)'
doesn't exist. Which is just false.Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: