I had data in my database. Now i want to add a column
$table->string('md5_url');
It work. But now i want to add unique index on md5_url. But it don't work because rows in my database have same value(=default value). So what should i do if i want to create new column form existed column(such as i want md5_url = md5(url_column_value)
I have known 2 way to set default value.
$table->string('md5_url')->default($value);
and
$stack_links = DB::table('stack_links')->update(['md5_url' => $value]);
but 2 above way, the $value is fix, how to make it flexible (diffirent in each row) so that i can add unique index after that.
Note: i don't want to create model StackLink so don't try this way:
$stack_links = StackLink::get();
foreach($stack_links as $stack_link) {
$stack_link->md5_url = md5($stack_link->url);
$stack_link->save();
}
Update: have try
$table->string('md5_url')->default(uniqid());
but it don't work too.The result is