Reputation: 1
I got a problem when learning to create a schematic model of a prism, as below
model User {
id Int @id @default(autoincrement())
username String
email String @unique
password String
orders Order[]
products Product[]
}
model Product {
id Int @id @default(autoincrement())
name String
description String
price Int
stock Int
userId Int
user User @relation(fields: [userId], references: [id])
images Image[]
orders Order[]
}
model Image {
id Int @id @default(autoincrement())
url String
productId Int
product Product @relation(fields: [productId], references: [id])
}
model Order {
id Int @id @default(autoincrement())
quantity Int
totalPrice Int
orderDate DateTime
status String
userId Int
user User @relation(fields: [userId], references: [id])
productId Int
product Product @relation(fields: [productId], references: [id])
}
when I run the command "npm prisma migrate dev" an error message appears in the terminal like this
What should I do?
I've tried googling and looking for solutions on YouTube. But I don't understand, and I don't have anyone to ask either.
Upvotes: 0
Views: 17
Reputation: 13
In the error message it is saying that there are two rows currently in the table that this migration is going to cause a change to. The problem is that the new fields aren't marked as nullable, so when the update runs, your current data needs to be updated to make sure their new columns aren't null. This is leading to the error because prisma has no idea what to enter into those boxes, but has to enter something, and so fails.
Some examples but not an exhaustive list of how to fix this.
Upvotes: 0