Failed migrations won't let me deploy again

Yesterday I wanted to deploy again and it failed because of a failed migration. I added another field to a table with a value that shall be “TEXT NOT NULL” but that table already has some dummy entries.

So I want to follow the guide Migration troubleshooting in production | Prisma Docs but when I want to rollback a migration is tells me the following:

Migration `20220606170225_development_update` cannot be rolled back because it is not in a failed state.

I tried all the migrations I have and get the same message for all of them but it still doesn’t let me deploy on top of it.

I don’t really care about the data (yet) that is inside this table. How can I resolve this? I can not connect to the prod db with fly ssh console -C database-cli to do it myself (because its dead?).

Any help is appreciated, as I am quite new to fullstack stuff.

If I understand the problem right, you’ll need to delete the 20220606170225_development_update migration and then redeploy.

Prisma should be running migrations in transactions and rolling them back if they fail. But each time you deploy, it will try and run the migration again. Removing the failing migration should let the deploy continue.

Thank you for looking into this.
So I deleted the migrations in my project folder and it still fails at the same step.

I tried marking it as rolled-back as well as resolving but both don’t do anything.
I thought about just deleting the app on Fly and recreating it but that doesn’t solve my issue if it happens again in the future :confused:

Hey Aquila, this is Frederik, a PM at Prisma and you shared this link on Twitter.

I would recommend to use migrate status as it will tell you the state of your migration history and how that was applied to the DB (e.g. did any of the migrations fail or are some pending)

What you describe in your first message sounds like a typical migration that isnt possible.

If you add a column which can’t be null, but the table already has data, all exisiting rows would be invalid after the migrations (as their value would be null)

You need to create the column as nullable, set values for all the existing rows and then migrate the column to be not null.

Or you set a default value for the column.

I hope that helps, otherwise I could connect you with a support engineer to help you troubleshoot.

I am facing the similar situation and I agree with OP that we don’t always care about the existing data in the db, for example I am constantly pushing my changes in the staging environment mainly for the early feedback. I am fine with wiping my DB but I cannot find any easy way to do this.

I tried everything like deleted all the tables, deleted migration etc but it didn’t help.

I’m running into the same problem. And its so hard to get out of it. In my case the deployment failed so the app status is dead. Which means I can’t fly ssh console into it to then run npx prisma migrate status. Feels like a chicken and egg situation i.e. the app won’t deploy because of this issue and I can’t access console to fix this.

@floelhoeffel I’m able to access psql console using fly postgres connect but I’m not sure what I need to do there to make this issue go away.