Yii Framework Forum: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]:

#1 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 30 November 2010 - 05:52 AM

I am beginner in Yii framework. I was practicing through ebbok" Aggile WebDevelopment with Yii 1.1 ". I got following error in code when I clicked to Create Issue.
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.tbl_project_user_assignment(project_id' in 'where clause'

E:\xampp\htdocs\trackstar\protected\models\Project.php(113)

00101:
00102: return new CActiveDataProvider(get_class($this), array(
00103: 'criteria'=>$criteria,
00104: ));
00105: }
00106:
00107: /**
00108: * populate users
00109: */
00110: public function getUserOption()
00111: {
00112: $userArray = array();
00113: $userArray = CHtml::listData($this->users,'id','username');
00114: return $userArray;
00115:
00116: /*return array(
00117: self::USER_1=>'User1',
00118: self::USER_2=>'User2',
00119: );*/
00120: }

00121: }

Can anybody help me ?
0

#2 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 30 November 2010 - 12:22 PM

Can you provide the details of what your table looks like? Was your table created using the following sql?:

CREATE TABLE  `tbl_project_user_assignment`
(
  `project_id` Int(11) NOT NULL,
  `user_id` Int(11) NOT NULL,
  `create_time` DATETIME,
  `create_user_id` INTEGER,
  `update_time` DATETIME,
  `update_user_id` INTEGER,
 PRIMARY KEY (`project_id`,`user_id`)
) ENGINE = InnoDB
;

0

#3 User is offline   belltower 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 01-December 10

Posted 01 December 2010 - 10:44 PM

I had this error as well. It turns out I was doing:

'users' => array(self::HAS_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),

...instead of:

'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),

in the Project model's relations array.
0

#4 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 01 December 2010 - 10:58 PM

No I am using MySQL.

View Postjefftulsa, on 30 November 2010 - 12:22 PM, said:

Can you provide the details of what your table looks like? Was your table created using the following sql?:

CREATE TABLE  `tbl_project_user_assignment`
(
  `project_id` Int(11) NOT NULL,
  `user_id` Int(11) NOT NULL,
  `create_time` DATETIME,
  `create_user_id` INTEGER,
  `update_time` DATETIME,
  `update_user_id` INTEGER,
 PRIMARY KEY (`project_id`,`user_id`)
) ENGINE = InnoDB
;


0

#5 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 01 December 2010 - 11:03 PM

View Postddumitrescu, on 01 December 2010 - 10:44 PM, said:

I had this error as well. It turns out I was doing:

'users' => array(self::HAS_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),

...instead of:

'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),

in the Project model's relations array.


I am using the following relations:



public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'issue'=>array(self::HAS_MANY, 'Issue','project_id'),
'users'=>array(self::HAS_MANY,'user','tbl_project_user_assignment(project_id,user_id)'),
);
}

0

#6 User is offline   belltower 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 01-December 10

Posted 01 December 2010 - 11:06 PM

Yeah, that's how I had it too when I got the error. Try changing the 'users' one to MANY_MANY. It fixed it for me.
0

#7 User is offline   Coda 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 20-September 10
  • Location:Kathmandu, Nepal

Posted 02 December 2010 - 01:09 AM

View Postddumitrescu, on 01 December 2010 - 11:06 PM, said:

Yeah, that's how I had it too when I got the error. Try changing the 'users' one to MANY_MANY. It fixed it for me.


Yes you are right. There should be MANY_MANY relationship, as there is third table provided with FK so it must be MANY_MANY. Later I realize.
Thanks for you support too.Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users