Leonard Filip
05/10/2022, 11:52 AMmodel Author {
...
post Post?
}
// to
model Author {
...
post Post[]
}
I know I should also pluralise the relation field to posts but is this normal behaviour?Nurul
05/10/2022, 1:02 PMnpx prisma generate after making changes to schema file?Leonard Filip
05/10/2022, 1:22 PMschema.prisma changed. I am doing this change, post Post? -> posts Post[] on 3 different entities, all of them related to Post model. Each of these relations, Post -> Author , was originally modelled as 1to1 and this created unique constraints on each of the Post.*Id fields. When I implement the said change into schema.prisma , I would expect a new migration to be generated where these unique constraints on Post id fields would be dropped, and this doesn't happen.Leonard Filip
05/10/2022, 1:32 PMmodel Magazine {
id String @db.Char(36) @id @default(uuid())
...
image Image? @relation(fields: [imageId], references: [id])
imageId String? @db.Char(36)
attachment Attachment? @relation(fields: [attachmentId], references: [id])
attachmentId String? @db.Char(36)
flipDocument FlipDocument? @relation(fields: [flipDocumentId], references: [id])
flipDocumentId String? @db.Char(36)
}
model Attachment {
...
magazines Magazine[] // changed from 'magazine Magazine?'
}
// also same change for Image and FlipDocument
-- CreateTable
CREATE TABLE `Magazine` (
`id` VARCHAR(191) NOT NULL,
...
`imageId` VARCHAR(191) NULL,
`pdfId` VARCHAR(191) NULL,
`flipDocumentId` VARCHAR(191) NULL,
UNIQUE INDEX `Magazine_imageId_key`(`imageId`), -- removed
UNIQUE INDEX `Magazine_pdfId_key`(`pdfId`), --removed
UNIQUE INDEX `Magazine_flipDocumentId_key`(`flipDocumentId`), -- removed
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
And so I went into this weeks old migration file and manually removed those three UNIQUE constraints.Nurul
05/10/2022, 1:33 PMpost Post[] -> post? and the unique constraint was added and this change was picked up by migrate.
But reversing the change i.e. post? -> post[] didn’t automatically drop the unique constraint and this change wasn’t picked up by migrateLeonard Filip
05/10/2022, 1:34 PMNurul
05/10/2022, 1:51 PM