SQLSTATE[HY000]: General error: 1364 Field doesn't have a default value Laravel 8

SQLSTATE[HY000]: General error: 1364 Field doesn't have a default value Laravel 8

我正在做一个家庭项目,不是一个很好的编码员,我使用一个已经制作好的应用程序来编辑自己,我在我的产品 Table 中添加了多个列作为迁移:

public function up()
    {
        Schema::table('products', function (Blueprint $table) {
            //
            $table->integer('N_serie')->after('stock');
            $table->integer('quantite_fabrique')->after('N_serie');
            $table->unsignedDecimal('prix_qtt_fabrique', 10, 2)->after('quantite_fabrique');
            $table->integer('unite_lg')->after('prix_qtt_fabrique')->nullable();
            $table->integer('qtt_fabr_par_unit')->after('unite_lg')->nullable();
            $table->unsignedDecimal('prix_unite', 10, 2)->after('qtt_fabr_par_unit');
            $table->unsignedDecimal('prix_par_kg', 10, 2)->after('prix_unite');
            $table->unsignedDecimal('prix_1', 10, 2)->after('prix_par_kg')->nullable();
            $table->unsignedDecimal('prix_45', 10, 2)->after('prix_1')->nullable();
            $table->unsignedDecimal('prix_total', 10, 2)->after('prix_45')->nullable();
            $table->unsignedDecimal('comis_commerciale', 10, 2)->after('prix_total');
            $table->unsignedDecimal('prix_gros', 10, 2)->after('comis_commerciale');
        });
    }

我更改了可填充变量,并将这些附加到旧变量

    protected $fillable = [
            'name', 'description', 'product_category_id', 'price', 'stock','N_serie', 'quantite_fabrique','prix_qtt_fabrique','unite_lg','qtt_fabr_par_unit','prix_unite','prix_par_kg','prix_1','prix_45','prix_total','comis_commerciale','prix_gros','stock_defective'
        ];

I went to my view and added the new columns to the form, to be added, this is an example of one column code : 

   <div class="form-group{{ $errors->has('N_serie') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-name">N° de Série</label>
                                    <input type="text" name="name" id="input-name" class="form-control form-control-alternative{{ $errors->has('N_serie') ? ' is-invalid' : '' }}" placeholder="N° de Série" value="{{ old('N_serie') }}" required autofocus>
                                    @include('alerts.feedback', ['field' => 'N_serie'])
                                </div>

当我点击保存按钮时,出现了这个错误:

SQLSTATE[HY000]: General error: 1364 Field 'quantite_fabrique' doesn't have a default value (SQL: insert into products (price, category_id, updated_at, created_at) values (20, 3, 2020-12-11 07:00:34, 2020-12-11 07:00:34))

这是我的控制器功能,可以保存所有内容:

public function store(ProductRequest $request, Product $model)
    {
        $model->create($request->all());

        return redirect()
            ->route('products.index')
            ->withStatus('Product successfully registered.');
    }

不知道问题出在哪里,求助

您已将 quantite_fabrique 列设置为非空。您应该填写该字段。由于您使用的是 ProductRequest,因此您可以使用

public function store(ProductRequest $request)
    {
        if(Product::create($request->validated())){
          return redirect()
            ->route('products.index')
            ->withStatus('Product successfully registered.');
        }

        return redirect()
            ->route('products.index'); // throw your error here
    }

此外,您的 ProductRequest 必须有 'quantite_fabrique' 字段作为验证字段。

我的问题已解决,我没有编辑 ProductRequest class 来接受新添加的列并在请求中发送它们,这就是 [=13= 中不接受新列的原因] 代码“插入...” –