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])
}
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")
}
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)
- 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?
4 Replies
Prisma AI Help
Prisma AI Help5mo ago
You opted for speed from this bot. Let's conjure up an answer right now! You are seeing drift because your migration history and your actual database schema are out of sync—specifically, the nullability of the file_link_id column in FontVariant has changed back and forth, and Prisma Migrate is detecting this as drift. How to resolve without resetting the database: 1. Introspect the current database schema:
npx prisma db pull

npx prisma db pull

This updates your Prisma schema to match the current state of the database. 2. Generate a baseline migration: Use prisma migrate diff to create a migration that matches your current schema:
mkdir -p prisma/migrations/0_init
npx prisma migrate diff \
--from-empty \
--to-schema-datamodel prisma/schema.prisma \
--script > prisma/migrations/0_init/migration.sql

mkdir -p prisma/migrations/0_init
npx prisma migrate diff \
--from-empty \
--to-schema-datamodel prisma/schema.prisma \
--script > prisma/migrations/0_init/migration.sql

3. Mark the migration as applied:
npx prisma migrate resolve --applied 0_init

npx prisma migrate resolve --applied 0_init

4. Now, make your desired schema changes (add new fields, change nullability, etc.) in your Prisma schema file. 5. Create and apply a new migration:
npx prisma migrate dev

npx prisma migrate dev

This process "baselines" your current database, telling Prisma that the existing schema is the starting point, and future migrations will be tracked from there—no reset required. This is the recommended approach for existing databases where data loss is not acceptable see official guidance, discussion, and docs. Note: If you encounter issues with migration names, ensure you use the exact folder name created in the migrations directory when running migrate resolve. If you have further manual changes or drift, repeat the introspect and baseline process as needed. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul5mo ago
To confirm, the bot response of Baselining wasn't helpful?
Jacob Miller
Jacob MillerOP5mo ago
That is correct, but I did find the fix: After trying a dozen different things, creating a migration manually seems to do the trick: 1) Create the migration mkdir -p prisma/migrations/20250728130000_enforce_file_link_required cat > prisma/migrations/20250728130000_enforce_file_link_required/migration.sql <<EOF ALTER TABLE "FontVariant" ALTER COLUMN "file_link_id" SET NOT NULL; EOF 2) Tell Prisma it’s already been applied npx prisma migrate resolve \ --applied 20250728130000_enforce_file_link_required 3) Verify / run npx prisma migrate status npx prisma migrate dev
Nurul
Nurul5mo ago
Thanks for sharing your fix, it will be helpful to someone who might run into this

Did you find this page helpful?