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

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’



00102: return new CActiveDataProvider(get_class($this), array(

00103: ‘criteria’=>$criteria,

00104: ));

00105: }


00107: /**

00108: * populate users

00109: */

00110: public function getUserOption()

00111: {

00112: $userArray = array();

[size=“3”]00113: $userArray = CHtml::listData($this->users,‘id’,‘username’);[/size]

00114: return $userArray;


00116: /*return array(

00117: self::USER_1=>‘User1’,

00118: self::USER_2=>‘User2’,

00119: );*/

00120: }

00121: }

Can anybody help me ?

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

[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)



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.

No I am using MySQL.

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’),




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.