P
Prisma•3mo ago
JamesJGoodwin

Why would Prisma modify completely different table in scope of migration?

I have the following model
model RouteText {
id Int @id @default(autoincrement())
originSlug String
destinationSlug String
type RouteTextType
locale TranslationsType
value String @db.Text

AIGenerationMetadata AIGenerationMetadata? @relation(fields: [aiGenerationMetadataId], references: [id])
aiGenerationMetadataId Int?
originCity City @relation("OriginCityRouteText", fields: [originSlug], references: [slug], onDelete: Cascade)
destinationCity City @relation("DestinationCityRouteText", fields: [destinationSlug], references: [slug], onDelete: Cascade)

@@unique([originSlug, destinationSlug, type, locale])

}
model RouteText {
id Int @id @default(autoincrement())
originSlug String
destinationSlug String
type RouteTextType
locale TranslationsType
value String @db.Text

AIGenerationMetadata AIGenerationMetadata? @relation(fields: [aiGenerationMetadataId], references: [id])
aiGenerationMetadataId Int?
originCity City @relation("OriginCityRouteText", fields: [originSlug], references: [slug], onDelete: Cascade)
destinationCity City @relation("DestinationCityRouteText", fields: [destinationSlug], references: [slug], onDelete: Cascade)

@@unique([originSlug, destinationSlug, type, locale])

}
I'm trying to remove the unique constraint since there's no longer the need in this constraint, but for some reason Prisma is trying to modify completely irrelevant table.
-- DropForeignKey
ALTER TABLE `RouteText` DROP FOREIGN KEY `RouteText_originSlug_fkey`;

-- DropIndex
DROP INDEX `RouteText_originSlug_destinationSlug_type_locale_key` ON `RouteText`;

-- CreateIndex
CREATE INDEX `RouteText_originSlug_destinationSlug_type_locale_idx` ON `RouteText`(`originSlug`, `destinationSlug`, `type`, `locale`);

-- AddForeignKey
ALTER TABLE `AnswersOnAirports` ADD CONSTRAINT `AnswersOnAirports_airportCode_fkey` FOREIGN KEY (`airportCode`) REFERENCES `Airport`(`code`) ON DELETE CASCADE ON UPDATE CASCADE;
-- DropForeignKey
ALTER TABLE `RouteText` DROP FOREIGN KEY `RouteText_originSlug_fkey`;

-- DropIndex
DROP INDEX `RouteText_originSlug_destinationSlug_type_locale_key` ON `RouteText`;

-- CreateIndex
CREATE INDEX `RouteText_originSlug_destinationSlug_type_locale_idx` ON `RouteText`(`originSlug`, `destinationSlug`, `type`, `locale`);

-- AddForeignKey
ALTER TABLE `AnswersOnAirports` ADD CONSTRAINT `AnswersOnAirports_airportCode_fkey` FOREIGN KEY (`airportCode`) REFERENCES `Airport`(`code`) ON DELETE CASCADE ON UPDATE CASCADE;
Constraint addition of AnswersOnAirports_airportCode_fkey fails the migration because this constraint already exists. If I execute npx prisma migrate dev without any changes to schema, Prisma would tell me that there are no changes thus nothing to migrate. Where does this change coming from?
4 Replies
Prisma AI Help
Prisma AI Help•3mo ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
JamesJGoodwin
JamesJGoodwinOP•3mo ago
This appears to be a bug unfortunately... https://github.com/prisma/prisma/issues/26251
GitHub
Prisma creates invalid migration when removing an index · Issue #2...
Bug description For the simple schema below, when removing an index and then running a migration, prisma creates a migration that duplicates a previous foreign key constraint name. The duplicate co...
Nurul
Nurul•2mo ago
Does this workaround work for you in the meantime? https://github.com/prisma/prisma/issues/26251#issuecomment-3331015033
GitHub
Prisma creates invalid migration when removing an index · Issue #2...
Bug description For the simple schema below, when removing an index and then running a migration, prisma creates a migration that duplicates a previous foreign key constraint name. The duplicate co...
JamesJGoodwin
JamesJGoodwinOP•2mo ago
Yes, it was me actually who posted this workaround 🙂

Did you find this page helpful?