Failed migrations are not rolled back
See original GitHub issueMigrations should be run in transactions, just like in Knex, and they should be rolled back on failure.
My migration file is very simple…
const Schema = use('Schema')
class DocumentsSchema extends Schema {
up () {
this.create('documents', (table) => {
table.increments()
table.integer('user_id').unsigned().index().references('id').inTable('users')
})
}
down () {
this.drop('documents')
}
}
module.exports = DocumentsSchema
I ran node ace migration:run
. The migration failed with Cannot add foreign key constraint
but the table was not deleted aka the transaction was not rolled back. The migration error itself is fine, but why wasn’t the migration rolled back?
Discord discussion:
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
FluentMigrator Failed Migrations Don't Rollback?
I noticed that failed migrations are not being rolled back. Has this just not been implemented yet? This seems rather bad because it...
Read more >Failed migrations won't let me deploy again - Fly.io
Migration `20220606170225_development_update` cannot be rolled back because it is not in a failed state. I tried all the migrations I have ...
Read more >Migration troubleshooting in production - Prisma
There are two ways to deal with failed migrations in a production environment: Roll back ... Option 1: Mark the migration as rolled...
Read more >Dealing with Failed SQL Migrations in MariaDB or MySQL
The Problem: migrations that execute DDL can't be rolled back. Why didn't Flyway roll back the failed migration and let us try again?...
Read more >Flyway by Redgate • Database Migrations Made Easy.
This does not help with failed versioned migrations on databases without DDL transactions ... so you can simply roll back the application code,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After the failed migration, I just ran
node ace migration:rollback
and it ran ALL (~50) of thedown()
migrations (e.g. deleted 20 tables). After a successful migration this doesn’t happen, so something is clearly wrong here.MySQL is unable to transact DDL statements.
https://dev.mysql.com/doc/internals/en/transactions-notes-on-ddl-and-normal-transaction.html