Skip to content

I'm getting "Your database schema is not in sync with your migration history" every time I change something #23135

Description

@tigran1100

Bug description

Every time I want to make a change in my schema.prisma file, the terminal is saying that I have to reset my database.

For example this is my "Issues" mode

model Issue {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
description String @db.Text
status String @default("open")
created_at DateTime @default(now())
updated_at DateTime @updatedat
assigned_to_user_id String @db.VarChar(255)
assigned_to_user User? @relation(fields: [assigned_to_user_id], references: [id])
}

When I add new column, for example`
just_test_column String @db.Text

And the I run npx prisma migrate dev, it's asking me to reset my database.

How to reproduce

This is the error message`

PS E:\Win11Dev\Xampp\htdocs\issue-tracker-v4> npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "Issue_tracker" at "localhost:3306"

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 account table
[-] Removed foreign key on columns (userId)

[*] Changed the issue table
[-] Removed foreign key on columns (assigned_to_user_id)

[*] Changed the session table
[-] Removed foreign key on columns (userId)

× We need to reset the MySQL database "Issue_tracker" at "localhost:3306"
Do you want to continue? All data will be lost. ... no

Reset cancelled.

Expected behavior

I expect prisma to not require reset every time I change something

Prisma information

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

model Issue {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
description String @db.Text
descriptasdion String @db.Text
status String @default("open")
created_at DateTime @default(now())
updated_at DateTime @updatedat
assigned_to_user_id String @db.VarChar(255)
assigned_to_user User? @relation(fields: [assigned_to_user_id], references: [id])
}

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
assigned_issues Issue[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime

@@unique([identifier, token])
}

Environment & setup

  • OS: Windows 11
  • Database: MySql
  • Node.js version: 20.11.0

Prisma Version

"@auth/prisma-adapter": "^1.3.3",
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^5.9.1",
"prisma": "^5.9.1",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions