question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How Can I Disable Foreign Key?

See original GitHub issue

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

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:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sam-bungercommented, Feb 2, 2022

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

1reaction
tomhoulecommented, Jul 6, 2021

Ah, I think your prisma version is a bit too old, it probably was released around 2.24

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found