SQLSTATE[HY000]:常规错误:1364 字段'hours'没有默认值(SQL:插入到"工资单"() 值 ()) 中)



我正试图将属于employees表的'employee_id'插入到payrolls表中,但尽管有$fillable = ['over_time', 'notified','hours','rate', 'gross', 'employee_id'],我还是不断收到这个错误,对此有其他解决方案吗?

Schema::create('payrolls', function (Blueprint $table) { 
$table->bigIncrements('id'); $table->boolean('over_time')->default(0); 
$table->boolean('notified')->default(0);        
$table->integer('hours')->nullable(0);
$table->integer('rate')->nullable(0); 
$table->integer('gross')->nullable(0); 
$table->softDeletes(); $table->timestamps(); 
});

根据您的迁移,您已将hours列定义为nullablefalse,这意味着它不能为null,并且没有为该列定义default值。

由于某些原因,您的hours在请求中变为空白,这就是您收到此错误的原因。

$table->integer('hours')->nullable(0);

要解决此问题,请将默认值定义为小时列,如下所示,或将有效值传递给hours

$table->integer('hours')->default("00");

最新更新