-
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
How Can I Disable Foreign Key? #8108
Comments
Hi @linxixuan — what database are you using? We are discussing how we tackle this internally and want to work on an option to make migrate ignore relations (-> create no foreign keys) soon. In the meantime, you can add |
DB is mysql, our DBA suggest us do not use foreign key for some performance reason ;) |
@tomhoule hello, your solution is not work. Here is my env bugmy code
env$ npx prisma -v
prisma : 2.23.0
@prisma/client : 2.23.0
Current platform : darwin
Query Engine : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio : 0.393.0 |
Ah, I think your prisma version is a bit too old, it probably was released around 2.24 |
@linxixuan Did you try with the latest version to confirm we can close this issue? |
I'm having a similar issue where I need to disable foreign key constraints. I'm using Postgres. Here is my schema: model profiles {
id String @id
first_name String?
last_name String?
phone_number String @unique
phone_number_ref contacts[]
contacts_ref contacts[] @relation("contact_holder")
}
model contacts {
id Int @id
contact String?
contact_ref profiles? @relation(fields: [contact], references: [phone_number])
contact_holder String
contact_holder_ref profiles @relation("contact_holder", fields: [contact_holder], references: [id])
} Every profile has an ENV
|
Can you please open a new issue @sam-bunger? I think your problem is different. Thanks. |
Hey @janpio, the problems are different, but the ability to disable foreign key constraints would solve both of them. |
The current solution is described above: #8108 (comment) |
Hi @sam-bunger – did you manage to figure out how to solve your use-case? I'm hoping to achieve the same where I have a Postgres DB and need to set up a relation that does not have a foreign key constraint. |
Hey @bryanc208, I couldn't figure it out. We ended up deciding to stop using prisma for our project, so I haven't had the chance to look around and test if this solution really works, but from this looks of it this PR may have fixed the issue: prisma/prisma-engines#2221 |
for anyone searching for this and using planetscale in the future foreign key mode .
|
Problem
My DB can't use foreign key,If I specify the relation, Prisma will create foreign constraint automatically.
Suggested solution
I wonder how can I disable the foreign key constraint? All I need is the relation between two tables
So, is it possible
Some Info
here is the schema and sql created by prisma
The text was updated successfully, but these errors were encountered: