Reputation: 79
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
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