CDbCommand failed to execute the SQL statement

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’

Can anybody help me ?

Hi and welcome to the forum…

First of all you need to carefully select where to post your questions…

as this is related to the book and we have a subforum for it… would be nice if you post all book related questions there… The author of the book replays there…

Yii Book subforum - http://www.yiiframework.com/forum/index.php?/forum/38-yii-book-discussions/

As for the error… you need to again recheck all your steps with the book… as it says "unknown column"… it means that something is missing… or a column in the database… or some relation… or there is some typing error…

I was giving the book name for reference only from where I am using. But I have faced the problem so I posted.

Thanks for your response. I will check the relation which was created once. May be due to that …!!

The reason for this error is because the relations in your model file were specified as HAS_MANY, but the actual relation is coming from a MANY_MANY relationship in the database via an association table with a compound primary key.

an example to clarify:

Change this:





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(

			'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),

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

		);

	}






To this:





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(

			'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),

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

		);

	}






Hope this helps!