[英]"SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2018' for column 'created_at' at row 1 (SQL: insert into `news`
So, I am currently encountering with this error, the problem is when I want to create a new record this error occurs but when I update nothing happens, my DB is MySql and it is set to utf8, I have one local and one currently deployed, the one that I am deploying has utf8 but the local one has utf8mb4 I've looked at other questions similar to mine but I don't think they have the same solution.所以,我目前遇到了这个错误,问题是当我想创建一个新记录时会发生这个错误但是当我更新时什么也没有发生,我的数据库是 MySql 并且它被设置为 utf8,我有一个本地和一个当前部署,我正在部署的那个有 utf8 但本地有 utf8mb4 我看过其他与我类似的问题,但我认为他们没有相同的解决方案。
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2018' for column 'created_at' at row 1 (SQL: insert into
news
(title
,description
,date
,pictures
,categroy_id
,updated_at
,created_at
) values (zxczx,SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:第 1 行“created_at”列的“2018”(SQL:插入
news
(title
、description
、date
、pictures
、categroy_id
、updated_at
、created_at
)值(zxczx、xzxczxc
, 09/28/2018, ["3_1538054794.jpg"], 6, 2018-09-27 13:26:34, 2018-09-27 13:26:34))xzxczxc
, 09/28/2018, ["3_1538054794.jpg"], 6, 2018-09-27 13:26:34, 2018-09-27 13:26:34))
and that's how I save it这就是我保存它的方式
$new = new News;
$new->title = $input['title'];
$new->description = $input['description'];
$new->date = $input['date'];
$new->pictures = json_encode($pics);
$new->categroy_id = $input['category'];
$new->save();
You use Carbon to parse the date it will convert it to date format which is used by MySql YYYY-m-dd您使用 Carbon 来解析日期,它将其转换为 MySql YYYY-m-dd 使用的日期格式
$new = new News;
$new->title = $input['title'];
$new->description = $input['description'];
$new->created_at = Carbon::now();
$new->pictures = json_encode($pics);
$new->categroy_id = $input['category'];
$new->save();
Try like this :像这样尝试:
$new = new News;
$new->title = $input['title'];
$new->description = $input['description'];
$new->pictures = json_encode($pics);
$new->date = $input['date'];
$new->categroy_id = $input['category'];
$new->created_at = new \DateTime();
$new->save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.