Laravel 5.4升级-违反完整性约束-列不能为空 [英] Laravel 5.4 Upgrade -- Integrity constraint violation - Column cannot be null
本文介绍了Laravel 5.4升级-违反完整性约束-列不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
奇怪的是-所有这些都在5.2上运行,但是我不知道有什么改变可以实现这一目标.下面是错误和要插入的数组.
The strange thing is -- all of this was working at 5.2, but I don't know what could have changed to make this happen. Below is the error and the array being inserted.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'gender' cannot be null (SQL: insert into `tenants` (`name`, `phone`, `email`, `description`, `gender`, `date_birth`, `background_check_status`, `picture_url`, `work`, `position`, `country`, `location`, `hobbies`, `updated_at`, `created_at`) values (Amadeo Levy Luna, 18065496549, amadeo.luna@ttu.edu, , , 2017-05-08 20:29:50, 0, , , , , , , 2017-05-08 20:29:50, 2017-05-08 20:29:50)) ◀"
array:13 [▼
"_token" => "9HeacY4KskT5vpLPGCUTkzVxRcpcKMNjdob79aLs"
"name" => "Amadeo Levy Luna"
"phone" => "18065496549"
"email" => "amadeo.luna@ttu.edu"
"description" => null
"gender" => null
"background_check_status" => "0"
"picture_url" => null
"work" => null
"position" => null
"country" => null
"location" => null
"hobbies" => null
]
这在整个网站的许多不同领域都有所突破,但以前都没有突破. Laravel创建此功能后发生了什么变化?
This is breaking in many different fields all over the website, but none of them broke before. What changed in Laravel to create this?
推荐答案
假设代码中没有任何变化,我唯一想到的就是5.4中引入的两个新中间件:TrimStrings
和ConvertEmptyStringsToNull
.
Assuming nothing changed in your code the only thing I could think of is the two new middleware introduced in 5.4: TrimStrings
and ConvertEmptyStringsToNull
.
尝试在app\Http\Kernel.php
class Kernel extends HttpKernel
{
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
// ...
}
这篇关于Laravel 5.4升级-违反完整性约束-列不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文