У меня есть приложение, построенное на платформе CakePHP 2.7, и когда я иду, чтобы загрузить страницу входа, он выдает мне следующую ошибку: Integrity constraint violation: 1048 Column 'userid' cannot be null
, Я знаю, что в своей пользовательской модели я должен установить ее не равной NULL, но что бы я изменил, чтобы убедиться, что это просто », а не NULL? Я включил мою модель пользователя ниже. Любая помощь будет принята с благодарностью!
Модель пользователя
<?php
class User extends AppModel {
var $name = 'User';
var $primaryKey = 'userid';
var $displayField = 'username';
var $hasAndBelongsToMany = array(
'Team' => array(
'className' => 'Team',
'joinTable' => 'teamAssignments',
'foreignKey' => 'userid',
'associationForeignKey' => 'teamid',
'unique' => 'true'
)
);
var $hasMany = array(
'Assessment' => array(
'className' => 'Assessment',
'foreignKey' => 'student_id'
),
'Assessment' => array(
'className' => 'Assessment',
'foreignKey' => 'teacher_id'
),
'AssessmentComment' => array(
'className' => 'AssessmentComment',
'foreignKey' => 'student_id'
),
'AssessmentComment' => array(
'className' => 'AssessmentComment',
'foreignKey' => 'teacher_id'
),
'Tour' => array(
'className' => 'Tour',
'foreignKey' => 'userid'
),
'Wiki' => array(
'className' => 'Wiki',
'foreignKey' => 'user_id'
)
);
function archive($id) {
if (!$id) {
return false;
}else{
$this->recursive = -1;
$user = $this->read(null, $id);
$user['User']['active'] = false;
$this->save($user);
return true;
}
}
function getInfo($id, $team_id, $token) {
$user = $this->read(null, $id);
// Make sure the token is valid
$this->Tour->recursive = 2;
$tour = $this->Tour->findByToken($token);
if ($team_id == '_definst_') {
// This is the global chat application or some other exception
$user = $this->read(null, $id);
$info['userid'] = $user['User']['userid'];
$info['firstName'] = $user['User']['firstName'];
$info['lastName'] = $user['User']['lastName'];
$info['emailAddress'] = $user['User']['emailAddress'];
$info['logincount'] = $user['User']['logincount'];
$info['lastlogin'] = $user['User']['lastlogin'];
$info['mentor'] = $user['User']['mentor'];
return http_build_query($info);
}else if ($tour) {
// Make sure this user has permission to look at this team
$on_team = false;
if ($tour['User']['mentor'] == 1) {
$on_team = true;
}else{
foreach ($tour['User']['Team'] as $team) {
if ($team['id'] == $team_id) {
$on_team = true;
break;
}
}
}
if ($on_team) {
// Make sure the requested user is on the requested team
$user = $this->read(null, $id);
$on_team = false;
if ($tour['User']['mentor'] == 1) {
$on_team = true;
}else{
foreach ($user['Team'] as $team) {
if ($team['id'] == $team_id) {
$on_team = true;
break;
}
}
}
if ($on_team) {
$team = $this->Team->read(null, $team_id);
$info['userid'] = $user['User']['userid'];
$info['username'] = $user['User']['username'];
$info['firstName'] = $user['User']['firstName'];
$info['lastName'] = $user['User']['lastName'];
$info['emailAddress'] = $user['User']['emailAddress'];
$info['teacher'] = $user['User']['teacher'];
$info['logincount'] = $user['User']['logincount'];
$info['lastlogin'] = $user['User']['lastlogin'];
$info['mentor'] = $user['User']['mentor'];
$info['teamid'] = $team['Team']['id'];
$info['teamName'] = $team['Team']['teamName'];
$info['instancename'] = $team['Team']['instanceName'];
return http_build_query($info);
}
}
return '';
}
}
function validate($token, $team_id) {
$this->Tour->recursive = 2;
$tour = $this->Tour->findByToken($token);
if ($team_id == '_definst_') {
// This is the global chat application or some other exception
return $tour['Tour']['userid'];
}else if ($tour) {
// Make sure this user is on this team or is a mentor
$on_team = false;
if ($tour['User']['mentor'] == 1) {
$on_team = true;
}else{
foreach ($tour['User']['Team'] as $team) {
if ($team['id'] == $team_id) {
$on_team = true;
break;
}
}
}
if ($on_team) {
return $tour['Tour']['userid'];
}
}
return '';
}
function wsKillSession($token) {
// Delete any tours
$this->Tour->recursive = -1;
$tour = $this->Tour->findByToken($token);
$this->Tour->deleteAll(array('Tour.userid' => $tour['Tour']['userid']));
return 1;
}
function getUsers($user_id, $token, $team_name) {
$user = $this->read(null, $user_id);
$team = $this->Team->find('first', array('conditions' => array('Team.teamName' => $team_name)));
$users = array();
foreach ($team['User'] as $user) {
$users[] = array('userid' => $user['userid'], 'username' => $user['username'], 'firstName' => $user['firstName'], 'lastName' => $user['lastName'], 'emailAddress' => $user['emailAddress'], 'teacher' => $user['teacher'], 'logincount' => $user['logincount'], 'lastlogin' => $user['lastlogin'], 'mentor' => $user['mentor'], 'teamid' => $team['Team']['id'], 'teamName' => $team['Team']['teamName'], 'instanceName' => $team['Team']['instanceName']);
}
return serialize($users);
}
}
?>
Задача ещё не решена.
Других решений пока нет …