违反完整性约束:1048列"class_code"不能为空 [英] Integrity constraint violation: 1048 Column 'class_code' cannot be null
问题描述
My controller:
$class = new joinclass();
$class -> user_id = Auth::user()->id;
$class -> class_code = $request['class_code'];
$class -> save();
Class_code
是另一个表列名称.它不是主键或外键.
Class_code
is another table column name. It's not primary key or foreign key.
推荐答案
您的字段"class_code"
包含"nothing"(空),并且您的MySQL服务器正在严格"模式下运行.
从MySQL 5.7.5开始,默认的SQL模式包括STRICT_TRANS_TABLES
,这正是造成您头痛的原因.
Your field "class_code"
contain "nothing" (null) and Your MySQL server is running in "strict" mode.
As of MySQL 5.7.5, the default SQL mode includes STRICT_TRANS_TABLES
, which is exactly the cause of your headache.
要更改服务器的模式,请编辑my.cnf
(如果正在运行Windows,则为my.ini
),并将模式设置为:
To change your server's mode, edit your my.cnf
(or my.ini
if you're running Windows) and set the mode to:
sql-mode=""
然后,您必须像这样重新启动mysql服务器:
Then you must restart your mysql server like this:
service mysql reload
或直接抛出init.d进程:
Or directly throw init.d process:
/etc/init.d/mysql reload
希望它会对您有所帮助.
Hope it will help you.
这篇关于违反完整性约束:1048列"class_code"不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!