Integrity constraint violation: 1048 Column 'class_code' cannot be null

試著忘記壹切 提交于 2019-12-12 05:17:50

问题


My controller:
$class = new joinclass();
$class -> user_id = Auth::user()->id;
$class -> class_code = $request['class_code'];
$class -> save();

Class_code is another table column name. It's not primary key or foreign key.


回答1:


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.

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=""

Then you must restart your mysql server like this:

service mysql reload

Or directly throw init.d process:

/etc/init.d/mysql reload

Hope it will help you.



来源:https://stackoverflow.com/questions/39181916/integrity-constraint-violation-1048-column-class-code-cannot-be-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!