Issues with the migrate down command.

I have my database with some tables doing development and such, then i decided to install an extension that adds a new database table via migrations, i.e: this.

All good and dandy, then i add a few more tables and finally i spot that i did a mistake and have to migrate down all the tables.

Now the problem is that the migration command cannot find the migration for the above extension and it errors out not allowing me to do a full migration down.

How do you fix this type of issue? Is there a flag to make the migrate command skip missing migration files?

You intentionally tried to remove the entry from the migration table.

But, did it work as expected? I guess the entry for the extension still exists.

I think you can manually remove the entry, or modify the migration history.

http://www.yiiframework.com/doc-2.0/guide-db-migrations.html#modifying-migration-history

@softark - That change has been done after i posted the thread, to avoid this issue and it works fine ;)

The migration history is added after it has been successfully applied. So trying to remove the history in “up” method doesn’t make sense.

That makes sense, i already remove dthe migration that’s why i was under the impression it has been removed.

Maybe put the code in __destruct() ? Any other way that doesn’t need to call the migrate command?

I think the afterAction event is good enough:


// remove us from the migration table.

        app()->controller->on(Controller::EVENT_AFTER_ACTION, function() {

            $version = (new \ReflectionClass($this))->getShortName();

            db()->createCommand()->delete(app()->controller->migrationTable, 'version = :v', [':v' => $version])->execute();

        });