How Can I Disable Foreign Key?
See original GitHub issueProblem
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
model Post {
id Int @id @default(autoincrement())
updateAt DateTime @default(now())
title String
type String
url String @unique
tags String
authorId Int?
likes Int @default(0)
isDelete Boolean @default(false)
user User? @relation(fields: [authorId], references: [id])
weeklyPosts WeeklyPosts[]
@@index([authorId], name: "authorId")
}
CREATE TABLE `Post` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`updateAt` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`title` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`type` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`url` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`tags` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`authorId` int(11) DEFAULT NULL,
`likes` int(11) NOT NULL DEFAULT '0',
`isDelete` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Post.url_unique` (`url`),
KEY `authorId` (`authorId`),
CONSTRAINT `post_ibfk_1` FOREIGN KEY (`authorId`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
sql - How can I temporarily disable a foreign key constraint in ...
In your table, go to the SQL tab · After you edit the SQL command that you want to run, there is a...
Read more >MySQL - How to temporarily disable a foreign key constraint?
MySQL - How to temporarily disable a foreign key constraint? · SET FOREIGN_KEY_CHECKS=0; · SET FOREIGN_KEY_CHECKS=1; · ALTER TABLE table_name ...
Read more >SQL Server: Disable a foreign key - TechOnTheNet
Once you have created a foreign key in SQL Server, you may encounter a situation where you are required to disable the foreign...
Read more >How to Disable Foreign Key Check in MySQL - Ubiq BI
You can disable foreign key check in MySQL by setting the system variable foreign_key_checks to 0. SET foreign_key_checks = 0. Similarly, you ...
Read more >How to Disable Foreign Key Constraint Checks in MySQL
Drop tables that have foreign key constraints · Drop the table cities first and then remove the table countries . · Disable foreign...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
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
Ah, I think your prisma version is a bit too old, it probably was released around 2.24