Error parsing attribute "@relation": The type of the field `<field>` in the model `<model>` is not matching the type of the referenced field `id` in model `<model2>`.
See original GitHub issueBug description
prisma introspect
with native types produces invalid schema.
How to reproduce
- Deploy the following SQL
CREATE TABLE public.grading_periods (
id bigint NOT NULL,
grading_period_group_id integer NOT NULL
);
ALTER TABLE ONLY public.grading_periods
ADD CONSTRAINT grading_periods_pkey PRIMARY KEY (id);
CREATE TABLE public.grading_period_groups (
id bigint NOT NULL
);
ALTER TABLE ONLY public.grading_period_groups
ADD CONSTRAINT grading_period_groups_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.grading_periods
ADD CONSTRAINT fk_rails_9cc118401a FOREIGN KEY (grading_period_group_id) REFERENCES public.grading_period_groups(id);
prisma introspect
(withnativeTypes
flag) produces
model grading_period_groups {
id BigInt @id @db.BigInt
grading_periods grading_periods[]
}
model grading_periods {
id BigInt @id @db.BigInt
grading_period_group_id Int @db.Integer
grading_period_groups grading_period_groups @relation(fields: [grading_period_group_id], references: [id])
}
prisma validate
returns
(base) divyendusingh [prisma-explicit-panic]$ yarn prisma validate
yarn run v1.22.4
$ /Users/divyendusingh/Documents/prisma/triage/prisma-explicit-panic/node_modules/.bin/prisma validate
Prisma schema loaded from schema.prisma
Error: Schema parsing
error: Error parsing attribute "@relation": The type of the field `grading_period_group_id` in the model `grading_periods` is not matching the type of the referenced field `id` in model `grading_period_groups`.
--> schema.prisma:19
|
18 | grading_period_group_id Int @db.Integer
19 | grading_period_groups grading_period_groups @relation(fields: [grading_period_group_id], references: [id])
20 | }
|
Prisma information
(base) divyendusingh [prisma-explicit-panic]$ yarn prisma --version 130 ↵
yarn run v1.22.4
$ /Users/divyendusingh/Documents/prisma/triage/prisma-explicit-panic/node_modules/.bin/prisma --version
@prisma/cli : 2.16.0-dev.17
@prisma/client : 2.16.0-dev.17
Current platform : darwin
Query Engine : query-engine d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio : 0.343.0
Preview Features : nativeTypes
✨ Done in 1.75s.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
prisma introspect generate invalid model - Stack Overflow
@relation error msg in : Error parsing attribute "@relation": The type of the field userId in the model posts is not matching the...
Read more >error parsing attribute @relation: a one-to-one relation must ...
> Error parsing attribute "@relation": The `onDelete` referential action of a relation must not be set to `SetNull` when a referenced field is...
Read more >Special rules for referential actions in SQL Server and MongoDB
With MongoDB, using referential actions in Prisma requires that for any data model with self-referential relations or cycles between three models, ...
Read more >Selectors Level 4 - W3C
an E element that does not match either compound selector s1 or compound ... Note: Some document models normalize case-insensitive attribute ...
Read more >Oracle Data Integrator Best Practices for a Data Warehouse
Other Non Relation Models . ... ID is set to “not null” in the data model ... Flex Fields are attributes that you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
An alternative workaround here might be to lie to Prisma. Instead of trying to generate a client with two non matching columns in the relation, change the bigger one to actually have the type of the smaller one. This will not reflect reality, but e.g. for Int and BigInt this should be fine assuming your data confirms to that and does not include BigInts. Then the error should go away, you should be able to use the full API of Prisma on your models.
(Although a discussion happens here, this is in the end “just” a feature request to enable this behavior. If we want to keep guidance for users around how to handle this specific case, we should put it into our documentation as a workaround for a limitation (“Prisma does not support foreign keys with different data types - this is what you can do to work with that database in Prisma anyway”).
answering my own question
i just commented out the lines in question. obviously, this means i cannot use prisma to access any of these values, however, it means that i can fix them as i need to. (i am slowly porting a legacy code base over to prisma)