我有這個條件的驅動程序模式:1366不正確的十進制值Laravel
protected $fillable = [
'hourly_rate',
'ot_hourly_rate',
'commission_rate',
'basic_salary',
'join_date',
];
,這裏是我的移民代碼:
public function up()
{
Schema::table('drivers', function ($table) {
$table->integer('hourly_rate', 24,2)->nullable()->default(0);
$table->decimal('ot_hourly_rate', 24,2)->nullable()->default(0);
$table->decimal('commission_rate', 24,2)->nullable()->default(0);
$table->decimal('basic_salary', 24,2)->nullable()->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('drivers', function ($table) {
$table->dropColumn('hourly_rate');
$table->dropColumn('ot_hourly_rate');
$table->dropColumn('commission_rate');
$table->dropColumn('basic_salary');
});
}
的問題是,當我嘗試創建驅動程序並沒有填寫那些表示錯誤十進制值的字段。十進制不能將空字符串作爲NULL存儲在數據庫中?
注意:這些字段不是必需的。
爲什麼你有空和默認?當新行被添加時,你希望它默認爲0還是null?嘗試添加'default('0')'看看會發生什麼。 – usrNotFound