Allie Syadiqin
Allie Syadiqin

Reputation: 79

Laravel Artisan - How to add and populate a new column into a table with existing records?

I wanted to add a new unique column called uuid into an existing table. This is my migration function.

public function up()
{
    Schema::table('suppliers', function (Blueprint $table) {
        $table->uuid('uuid')->index()->after('id');
    });
}

However, the table already has existing records, ie 100+ records. How do I create a function to populate this new column with unique values for the existing records? Thanks.

Upvotes: 0

Views: 514

Answers (1)

Ali
Ali

Reputation: 776

you have to specify the type of the column so change $table->uuid to $table->string. so try following.

Schema::table('suppliers', function (Blueprint $table) {
    $table->integer('uuid')->unique()->after('id');
});

Upvotes: 1

Related Questions