Laravel PHP Artisan: No matching table column found - read-only access
P粉547362845
P粉547362845 2024-02-25 15:12:02
0
2
400

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粉547362845
P粉547362845

reply all(2)
P粉546257913

I just restarted my database tools and it went away.

P粉504920992

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!