question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed migrations are not rolled back

See original GitHub issue

Migrations 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: screen shot 2018-03-21 at 14 39 54

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
simontaborcommented, Mar 21, 2018

After the failed migration, I just ran node ace migration:rollback and it ran ALL (~50) of the down() migrations (e.g. deleted 20 tables). After a successful migration this doesn’t happen, so something is clearly wrong here.

1reaction
moltarcommented, May 8, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found