简体   繁体   English

“SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:'2018'列'created_at'在第 1 行(SQL:插入到`news`

[英]"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:插入newstitledescriptiondatepicturescategroy_idupdated_atcreated_at )值(zxczx、

xzxczxc xzxczxc

, 09/28/2018, ["3_1538054794.jpg"], 6, 2018-09-27 13:26:34, 2018-09-27 13:26:34)) , 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.

相关问题 SQLSTATE [22007]:无效的日期时间格式:1292错误的日期时间值:第1行的“ created_at”列为“ 1970-01-01 00:00:01” - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1970-01-01 00:00:01' for column 'created_at' at row 1 SQLSTATE[22007]:无效的日期时间格式:1292 日期时间值不正确 - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value Laravel 将时间戳保存为 DateTime - SQLSTATE[22007]:日期时间格式无效:1292 日期时间值不正确: - Timestamp being saved as DateTime by Laravel - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: SQLSTATE [22007]:日期时间格式无效:1292 日期时间值不正确:“fotostudio”列的“28-01-2022 12:00”。“transaction_details” - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '28-01-2022 12:00' for column `fotostudio`.`transaction_details` Laravel - SQLSTATE [22007]:无效的日期时间格式:1292 不正确的日期时间值:'1616818311712' - Laravel - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1616818311712' LARAVEL:SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值 - LARAVEL : SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value 如何修复'SQLSTATE [22007]:无效的日期时间格式:1292截断了错误的DOUBLE值:'X' - How to fix 'SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: 'X'' Eloquent 删除 - SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值: - Eloquent Delete - SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: SQLSTATE [22007]:无效的日期时间格式:1366错误的整数值:行1的列'infraction_id'的'[“ 1”,“ 3”,“ 66”,“ 68”]' - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '[“1”,“3”,“66”,“68”]' for column 'infraction_id' at row 1 SQLSTATE [22007]:无效的日期时间格式:1366不正确的整数值 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM