Prismaのデプロイで Error: P3009 migrate found failed migrations in the target database, new migrations will not be applied. が出たので対処した
Cloud SQL に prisma deploy した時に
Error: P3009 migrate found failed migrations in the target database, new migrations will not be applied. ... The `20220515100619_foo` migration started at ...
というエラーが出た。
このエラーが出たマイグレーションは NOT NULL なカラムを追加するものだったのだが、そのテーブルが既にデータを持っていたので失敗してしまっていた。
手動でテーブルからデータを削除して再度デプロイを試みたが失敗した。
解決法
_prisma_migrationsテーブルから該当のマイグレーションの履歴を削除して再度ビルドする。
SELECT id FROM _prisma_migrations where migration_name='20220515100619_foo'; DELETE FROM _prisma_migrations where id='<ID>';