Hello!
I have a table with the following column:
$table->tinyInteger('wear_count')->default(7);
I want to change its default value. Found out along the way that tinyInteger cannot be changed. I change with the following command:
$table->smallInteger('wear_count')->default(14)->change();
Is it possible to change the default values to something else (14) only for those entries that have not been changed. Or that have not been changed since a certain date. That is, if users have already changed this value for themselves, is it possible to leave them unchanged, and change the rest of the records to 14.
And how to do it in migration with Eloquent? I'm trying this code:
public function up()
{
Schema::table('deals', function (Blueprint $table) {
$table->smallInteger('wear_count')->default(14)->change();
$table->update(['wear_count' => 14]);
});
}
Why is this code in the Class inherited from Migration not working? The error is displayed: 'Method Illuminate Database Schema Blueprint :: update does not exist.' Which class does the update method belong to?
It can be done in the migration but I would say it's a bit of a bad practice.
You could do it in a seeder but that is not quite right either.
However I take it you only want to do it once then I'd use a script directly in the database to handle that rater than complicate it by doing it with php.
If you one the other hand need to run it on multiple servers then I'd probably put it in a seeder.
Thank you all for your help. I work more with the frontend, but for the project I had to deal with Laravel a little, so I ask such questions ... In my case, it is better to use a SQL command to change the data in the table and one new Migration to set a new default value for the column. Thank you again for your help, a good team has gathered on this forum :)