-
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
"called Option::unwrap()
on a None
value" on mismatch between Prisma and database schema
#21219
Comments
@jlkravitz thanks for the report, could you please provide the missing information so we could reproduce the issue (the query that is failing and the schema)? |
@aqrln Just added a minimal example based on my code that produces the error. (Note that the error persists even if I copy the data from the |
Hi @aqrln I did some more digging. The issue is related to #13340. I marked the column |
Option::unwrap()
on a None
valueOption::unwrap()
on a None
value" on mismatch between Prisma and database schema
@jlkravitz That makes a lot of sense. Optimally Prisma would of course not crash here, but return some useful error message to the user what went wrong - according to your description it queried for 1 entry (as indicated by the relation and But I have trouble to reproduce the situation you are describing. When I try to manually create a schema similar to the one above, 2 tables with a relation to a non-unique field, with this SQL: -- CreateTable
CREATE TABLE [dbo].[actions] (
[id] INT NOT NULL IDENTITY(1,1),
[request_id] INT NOT NULL,
CONSTRAINT [actions_pkey] PRIMARY KEY CLUSTERED ([id])
);
-- CreateTable
CREATE TABLE [dbo].[request2] (
[id] INT NOT NULL IDENTITY(1,1),
[request_id] INT NOT NULL,
CONSTRAINT [request2_pkey] PRIMARY KEY CLUSTERED ([id]),
-- CONSTRAINT [request2_request_id_key] UNIQUE NONCLUSTERED ([request_id])
);
-- AddForeignKey
ALTER TABLE [dbo].[actions] ADD CONSTRAINT [actions_request_id_fkey] FOREIGN KEY ([request_id]) REFERENCES [dbo].[request2]([request_id]) ON DELETE NO ACTION ON UPDATE CASCADE;
(Note the commented out I get an error message from SQL server on creation:
Seems SQL Server does not allow you to create a schema with a foreign key (to represent the relation) that points to a non unique column? Is this maybe where the views come in? |
@janpio I admit it's been a while since I encountered this issue, but if I recall - yes, this is where views come in. In theory, the view could be some complicated SQL query under the hood. There's a world in which I think one of the columns is unique (or at least I expect it to be), but am wrong perhaps because I made an incorrect assumption about the query. In this case, I marked the field as unique in the Prisma schema to improve ergonomics when querying with Prisma. But that was incorrect, so I got an error downstream that didn't make much sense at the time. |
Does that mean the |
Yes- isn't that by definition the case since this is a view? AFAIK, I
couldn't set up a foreign key onto a view, right?
Sent from iPhone
…On Fri, May 24, 2024 at 5:04 PM Jan Piotrowski ***@***.***> wrote:
Does that mean the @relation was also not really backed by a foreign key,
but that it only existed in the Prisma schema so that the API is generated
to use it like one? Then we could indeed end up in a situation that could
work like yours.
—
Reply to this email directly, view it on GitHub
<#21219 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWWZK6D7VP6LN6Q5V4UMQLZD6TOHAVCNFSM6AAAAAA5GKBKVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGM2TIMBZHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi Prisma Team! My Prisma Client just crashed. Perhaps related to #10586?
This is coming up repeatedly and really making it difficult to work with prisma...
This is the report:
Versions
Logs
Client Snippet
Schema
The text was updated successfully, but these errors were encountered: