Monday, February 27, 2017

[SOLVED]Laravel 5 - Use migrate:rollback with path

I've inserted a column with name im_useless to my table earlier which I do not need anymore.
This is my schema (filename: 2017_02_27_120313_units.php):
public function up()
{
    Schema::create('units', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('description');
        $table->string('im_useless');
        $table->timestamps();
    });
}

Now I try to remove it, so I used this code inside the down() function:
public function down()
{
    Schema::dropColumn('im_useless');
}

New Schema:
public function up()
{
    Schema::create('units', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('description');
        $table->timestamps();
    });
}

Now I have to rollback and then migrate again. I try to rollback only that specific migration file, by executing php artisan help migrate:rollback I found out that there is a --path option.
So I tried to rollback that specific migration like this:
php artisan migrate:rollback --path=2017_02_27_120313_units.php

But I get Nothing to rollback
How can I drop that specific column without having to rollback any other migrations?


UPDATE:
I think I have to change the path like this:
php artisan migrate:rollback --path=database/migrations/2017_02_27_120313_units.php
...since my php shell was opened in the project root folder?
However I still get Nothing to rollback
I also tried php artisan migrate --path=2017_02_27_120313_units.php and php artisan migrate --path=database/migrate/2017_02_27_120313_units.php
...and get Nothing to migrate

UPDATE 2
I think I have messed up my migrations table, because I removed the code inside the down() function and the table was never deleted. http://stackoverflow.com/a/26077506/4684797


via EdwardBlack

Advertisement