PrismaP
Prisma7mo ago
7 replies
Jacob Miller

Drift detected after making fields required

My db is cockroach.
I added two models,
model Font {
  id         String        @id @default(uuid())
  name       String        @unique
  created_at DateTime      @default(now())
  deleted_at DateTime?
  variants   FontVariant[] @relation("FontVariants")
}

model FontVariant {
  id           String    @id @default(uuid())
  name         String
  font_id      String
  created_at   DateTime  @default(now())
  deleted_at   DateTime?
  file_link_id String    @unique
  file_link    FileLink  @relation("FontFileLink", fields: [file_link_id], references: [id])
  font         Font      @relation("FontVariants", fields: [font_id], references: [id])
}

Initially, file_link_id and file_link were nullable. My next migration made those fields required. Migration was a success. However, then I added some fields. This was my new schema:
model Font {
  id              String        @id @default(uuid())
  name            String
  variants        FontVariant[] @relation("FontVariants")
  created_at      DateTime      @default(now())
  deleted_at      DateTime?
  owner_id        String
  visibility      Visibility    @default(INTERNAL)
  organization_id String?


  @@unique([name, owner_id])
  @@unique([name, organization_id])
  @@index([owner_id])
}


model FontVariant {
  id           String    @id @default(uuid())
  name         String    @unique
  font_id      String
  font         Font      @relation(fields: [font_id], references: [id], name: "FontVariants")
  created_at   DateTime  @default(now())
  deleted_at   DateTime?
  file_link_id String?   @unique
  file_link    FileLink? @relation(fields: [file_link_id], references: [id], name: "FontFileLink")
}

And then I got this error:
- Drift detected: Your database schema is not in sync with your migration history.

The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.

It should be understood as the set of changes to get from the expected schema to the actual schema.

[*] Changed the `FontVariant` table
  [*] Altered column `file_link_id` (changed from Nullable to Required)


reseting is not an option. How can I resolve this?
Was this page helpful?