You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
generate not identifying a unique criteria in introspected schema #2142
Updating to 2.0.0-beta.2 from 2.0.0-beta.1 causes generate to break on an introspected schema.
Error received:
Error validating: The argument `references` must refer to a unique criteria in the related model `metrics`. But it is referencing the following fields that are not a unique criteria: `metric_id`, `group_id`
How to reproduce
The schema is fairly complicated and I have not included related tables that are not referenced in the error. I have also renamed things with unrelated joins identified as other. It looks as follows:
model values {
metric_id Int
score Float
group_id Int
other1_id Int
other2_id Int
metrics metrics @relation(fields: [metric_id, group_id], references: [metric_id, group_id])
other2_groups other2_groups @relation(fields: [other1_id, other2_id, group_id], references: [other1_id, other2_id, group_id])
@@id([other1_id, other2_id, metric_id])
@@index([metric_id, group_id], name: "fk_group_metric")
@@index([metric_id], name: "metric_id")
@@index([other1_id, other2_id, group_id], name: "other1_id")
}
model metrics {
metric_id Int @default(autoincrement()) @id
name String
group_id Int
groups groups @relation(fields: [group_id], references: [group_id])
@@index([metric_id, group_id], name: "metric_group")
@@index([group_id], name: "group_id")
}
As you can see there is an index on [metric_id, group_id]. Regardless of this, any combination of a primary key (metric_id) with any other column will always be unique and should be allowed as a relation.
Expected behavior
Should generate properly. Was working in beta-1 without issue.
changed the title [-]beta.2 breaks generate functionality. Not identifying a unique criteria.[/-][+]beta.2 breaks generate functionality. Not identifying a unique criteria in introspected schema.[/+]on Apr 9, 2020
changed the title [-]beta.2 breaks generate functionality. Not identifying a unique criteria in introspected schema.[/-][+]generate not identifying a unique criteria in introspected schema[/+]on Sep 1, 2020
changed the title [-]generate not identifying a unique criteria in introspected schema[/-][+]`generate` not identifying a unique criteria in introspected schema[/+]on Sep 1, 2020
Hello, has this issue been fixed? I need to mirror a status column shared by two tables, and at this moment I am forced to first create a new item in the first table and then update the status in the second one with two separate operations.
I would really like to be able to use this native MySQL feature so that I can also assure that the operation is completed correctly without using any explicit transaction.
I have also found the issue #2182 which says that the problem has been fixed, but the parser still does not let me use non-unique indexes with the references keyword.
Activity
[-]beta.2 breaks generate functionality. Not identifying a unique criteria.[/-][+]beta.2 breaks generate functionality. Not identifying a unique criteria in introspected schema.[/+]pantharshit00 commentedon Apr 14, 2020
I can confirm this behaviour. The schema used for reproduction:
13 remaining items
[-]beta.2 breaks generate functionality. Not identifying a unique criteria in introspected schema.[/-][+]generate not identifying a unique criteria in introspected schema[/+][-]generate not identifying a unique criteria in introspected schema[/-][+]`generate` not identifying a unique criteria in introspected schema[/+]sn0wst0rm commentedon Nov 22, 2022
Hello, has this issue been fixed? I need to mirror a status column shared by two tables, and at this moment I am forced to first create a new item in the first table and then update the status in the second one with two separate operations.
I would really like to be able to use this native MySQL feature so that I can also assure that the operation is completed correctly without using any explicit transaction.
I have also found the issue #2182 which says that the problem has been fixed, but the parser still does not let me use non-unique indexes with the references keyword.
I hope you can let me know!
Thank you
Akxe commentedon Apr 24, 2023
@janpio This is supposed to be fixed, yet I, too, am getting the error. Do I need to set some option in
prisma.schemafile?