Is it possible through an Migration to use a replace to change a data record of an already populated table?

Asked

Viewed 14 times

-1

In the database there are already some data entered, and I need through an Migration to make a change to take the value that is there and change the "." by "/". Ex: there in ID 1, has the value field with 120.80, and I need this value to become 120/80, is it possible? (I don’t know if Migration would be the ideal to make this kind of change)

I tried this way, but I was only able to change the value in the bank to literally the word "value"

   public function up()
{
    Schema::table('participante_coleta_pressao_arterial', function (Blueprint $table) {
       //substituir o . por / nos dados que já estão populados
   $alter_valor = str_replace(".", "/", 'valor');

   DB::table ('participante_coleta_pressao_arterial')
   ->where('id', 1)
   ->update ([
       'valor' => $alter_valor
    
    ]); //
    
});
}

I would like to know a way that could reference that third parameter 'value' is the column value in the database table, and not a string with the 'value' content'

  • 1

    The Migrations are not for that purpose, well briefly the Migrations are to control the version of your database. I believe that a solution would be you create a command in Laravel to perform this update in the records.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.