Hi guys! Prisma doesn't pick up when I make change...
# orm-help
l
Hi guys! Prisma doesn't pick up when I make changes like so:
Copy code
model Author {
...
post Post?
}

// to

model Author {
...
post Post[]
}
I know I should also pluralise the relation field to
posts
but is this normal behaviour?
n
Hey Leonard 👋 the relation fields do not exist in the database, so the post column wouldn’t be in the database. When you say prisma doesn’t pick up changes, do you mean PrismaClient isn’t updated? Do you execute
npx prisma generate
after making changes to schema file?
l
Hello 🖐️ I want to mean that Prisma doesn't generate a new migration file even though
schema.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.
Copy code
model 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
Copy code
-- 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.
n
I see, I just made tried this change
post 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 migrate
l
This would be a bug, right? 😄
n
Let me check this with our team
🤔 1