后台环境:php Kohana
数据库:MySql
插入一条数据时catch到异常: "Creating default object from empty value"
try {
$newUser = ORM::factory('User');
$newUser->orgID = $orgID;
$newuser->staffID = $staffID;
$newUser->Firstname = $Firstname;
$newUser->Middlename = $Middlename;
$newUser->Lastname = $Lastname;
$newUser->email = $email;
$newUser->userTypeID = $userTypeID;
$newUser->phonenumber = $phonenumber;
$newUser->save();
$response_data['status'] = 'success';
$response_data['newuserID'] = $newUser->id;
} catch(Exception $e) {
$response_data['status'] = 'fail';
$response_data['error'] = $e->getMessage();
以上问题的原因是:
数据库配置变更时出现了问题,在表中已经存在一条数据的userTypeID字段是NULL值,此时变更数据库配置userTypeID为必填非空字段,与已有数据冲突。