I am developing a web using Laravel 9. I use the command sail php make:migration add_bought_to_products_table
to add a boolean column named "bought" to the products table. When trying to modify a value using the Eloquent helper(Product::where('id', $product->id)->update(array('bought'=>true))
The value in the database was not updated< /strong>. When looking at it, I found that the new field "Purchase" created by the migration was marked Read-only: There is no corresponding table column.
The migration code is as follows:
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('products', function (Blueprint $table) { $table->boolean('bought'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('products', function (Blueprint $table) { $table->dropColumn('bought'); }); } };
This is a screenshot of the database:
I have tried multiple times to clean the cache and rebuild the database and rollback and migrate again. The weird thing is that I had added the "visibility" field before and it worked perfectly using the exact same code and steps as the field I was having problems with.
How to solve?P粉5049209922024-02-26 00:01:36
After racking my brain, I solved the problem by simply restarting the docker container. It looks like this issue has nothing to do with Laravel, but with Docker!
For anyone encountering similar issues: Make sure to end Docker and all containers and restart.