我执行了一个查询,用status = 1
更新整个数据库(有一些限制(,并得到以下错误:
第一次执行:
Conversion failed when converting date and/or time from character string. (SQL: update [example] set [status] = 1, [updated_at] = 2020-11-26 14:13:38.1000 where [exampleId] = 1251)
第二次执行:
Conversion failed when converting date and/or time from character string. (SQL: update [example] set [status] = 1, [updated_at] = 2020-11-26 14:14:47.1000 where [exampleId] = 758)
第三次执行:
No errors.
这似乎与updated_at
列有关,但我不会手动更改该值。
更新功能:
$example= $this->dbExample->where(...)->first();
$example->status = true;
$example->save();
型号类别:
class Example extends Model
{
use SoftDeletes;
protected $table = 'example';
protected $primaryKey = 'exampleId';
protected $fillable = [...];
protected $hidden = ['created_at', 'status', 'updated_at'];
}
我该如何解决这个问题?
编辑1:
它总是在以.1000
结尾的时间戳上出错。
尝试将#dates数组添加到您的模型中:
class Example extends Model
{
use SoftDeletes;
protected $table = 'example';
protected $primaryKey = 'exampleId';
protected $fillable = [...];
protected $hidden = ['created_at', 'status', 'updated_at'];
protected $dates = [
'updated_at',
'created_at',
'deleted_at',
];
}