P
Prisma4mo ago
v28

renaming column names

Hello, In the past I've made some really bad naming decisions for my columns and I'm wanting to rename these now. current schema:
model CustomInstance {
id Int @id @default(autoincrement())
botStatusType BotStatusTypes
botStatusText String
}
model CustomInstance {
id Int @id @default(autoincrement())
botStatusType BotStatusTypes
botStatusText String
}
I would like to rename the botStatusType column to botActivityType. To do this I tried using the @map property, below is an example of how i tried this:
model CustomInstance {
id Int @id @default(autoincrement())
botStatusType BotStatusTypes @map(name: "botActivityType")
botStatusText String @map(name: "botActivityText")
}
model CustomInstance {
id Int @id @default(autoincrement())
botStatusType BotStatusTypes @map(name: "botActivityType")
botStatusText String @map(name: "botActivityText")
}
My database is populated full of data which cannot be removed, id like this schema change to be seemless, but when attempting to prisma db push I get the following error:
⚠️ We found changes that cannot be executed:
• Added the required column `botActivityText` to the `CustomInstance` table without a default value. There are 1 rows in this table, it is not possible to execute this step.
• Added the required column `botActivityType` to the `CustomInstance` table without a default value. There are 1 rows in this table, it is not possible to execute this step.
⚠️ We found changes that cannot be executed:
• Added the required column `botActivityText` to the `CustomInstance` table without a default value. There are 1 rows in this table, it is not possible to execute this step.
• Added the required column `botActivityType` to the `CustomInstance` table without a default value. There are 1 rows in this table, it is not possible to execute this step.
2 Replies
Prisma AI Help
Prisma AI Help4mo ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
jonfanz
jonfanz4mo ago
IMO you have two good options: - modify the generated migrations to be column renames instead of the delete/create pairs. - use the expand and contract pattern docs
How to migrate data with Prisma ORM using the expand and contract p...
Learn how to perform data migrations using the expand and contract pattern with Prisma ORM

Did you find this page helpful?