EdwardBlack EdwardBlack -4 years ago 119
PHP Question

Add new column to database table with migrations fails with - Nothing to migrate

I just learned how to use Migrations. I successfully created a table with this schema:

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('units', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
}


Unfortunattely I missed the column
path
, so I've tried to add it. First I informed myselfe in the laravel documentation to learn how to add new columns.

From the documentation:


The table method on the Schema facade may be used to update existing
tables.


My attempt:

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('units', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});

Schema::table('units', function (Blueprint $table) {
$table->string('path');
});
}


However, after executing
php artisan migrate
I get
Nothing to migrate
.

What am I doing wrong?

Answer Source

You'll need to rollback migration first which will destroy last migration tables with all data:

php artisan migrate:rollback

And then run php artisan migrate command again. It's the best option while app is in development.

If you don't want to do that for some reason (app is live etc), but just want to add a column then create a new migration and add this code:

public function up()
{
    Schema::table('units', function (Blueprint $table) {
        $table->string('path');
    });
}

And run these commands:

composer dumpauto
php artisan migrate
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download