shmuels
shmuels

Reputation: 1393

Prisma db push error when removing column that has a default value

After removing a column from schema.prisma, and running npm prisma db push, I'm getting the error...

Error: The object 'users_role_df' is dependent on column 'role'.

I'm using Prisma 3.3.0 with the sqlserver connection.

The model looks like this...

model User {
    id ....
    name ...
    role String @default("USER")
}

I see the initial push created the CONSTRAINT users_role_df but now when I remove it from the model, and run push, it's not handling removing the constraint first and then the column.

How can I fix this?

Upvotes: 1

Views: 2517

Answers (1)

Tasin Ishmam
Tasin Ishmam

Reputation: 7198

You could try running the command npx prisma migrate dev --create-only to see what the generated SQL looks like for the migration.

You could manually add a DROP CONSTRAINT users_role_df; inside the generated migration or change the order of the SQL commands (if such a command already exists in the generated migration).

It is fine for you to make changes to the migration file as long as you do it before applying the migration to your database.

Upvotes: 2

Related Questions