问题
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