首頁  >  問答  >  主體

Laravel PHP Artisan:找不到符合的表格列 - 只讀訪問

我正在使用 Laravel 9 開發一個 Web。我使用指令 sail php make:migration add_bought_to_products_table 在產品表中新增一個名為「bought」的布林列。當嘗試使用Eloquent 幫助程式修改值時(Product::where('id', $product->id)->update(array('bought'=>true)) 資料庫中的值未更新< /strong>.當查看它時,我發現遷移創建的新字段“購買”被標記為只讀:沒有相應的表列

遷移程式碼如下:

<?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');
        });
    }
};

這是資料庫的螢幕截圖:

我已經多次嘗試清理快取並重建資料庫,並再次進行回滾和遷移。奇怪的是,我之前添加了“可見性”字段,它與出現問題的字段使用完全相同的程式碼和步驟完美地工作。

如何解決?

P粉547362845P粉547362845211 天前402

全部回覆(2)我來回復

  • P粉546257913

    P粉5462579132024-02-26 11:43:04

    我只是重新啟動了我的資料庫工具,它就消失了。

    回覆
    0
  • P粉504920992

    P粉5049209922024-02-26 00:01:36

    在我絞盡腦汁之後,我透過簡單地重新啟動 docker 容器來解決了這個問題。看來這個問題與 Laravel 無關,而是與 Docker 有關!

    對於遇到類似問題的任何人:確保結束 Docker 和所有容器並重新啟動。

    回覆
    0
  • 取消回覆