dallardtech
dallardtech

Reputation: 185

Updating table scheme without affecting data in Laravel

I am new to Laravel from code igniter and I am LOVING THE FRAMEWORK! My life is so much easier now.

I have created a table with columns using php artisan and entered some test data. I now want to add a few new columns to the database without affecting the current data, and setting the new fields to be null.

My inital thought was to enter a new field in the database migrate file and the run "php artisan migrate", but this just gave me the message "nothing to migrate" and did enter the new column in my database.

Here is my database migrate file:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateFestivalsTable extends Migration {

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

}

public function down()
{
    Schema::drop('festivals');
}

}

Upvotes: 11

Views: 12610

Answers (1)

umefarooq
umefarooq

Reputation: 4574

create new migration with artisan name it addColumnFestivalTable

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class addColumnFestivalTable extends Migration {

public function up()
{
    Schema::table('festivals', function($table)
    {
        $table->string('new_col_name');
     });

}

public function down()
{
    Schema::table('festivals', function($table)
    {
       $table->dropColumn('new_col_name');
    });
}

}

for more information read Laravel 5.4 doc

Upvotes: 31

Related Questions