Column Name Must Be Either A String Or An Array.

i have a simple code that is supposed to keep track of history of last visited url in the database for a given model.

i have inserted the following code in the AR model :

public function manageHistory()


		$user = Yii::app()->user->getId(); 

		$history=History::model()->find('user_id=:userID', array(':userID'=>$user));

		if (empty($history)) 

		{ // no history so create the 1st visted record

			$history = new History; 

			$history->user_id = $user; 

			$history->lesson_id = $this->lesson_id; 



		 if (!empty($history)) 

		 { //update the existing record with new record

				$history->lesson_id = $this->lesson_id; 





This code gives me the following error:

Column name must be either a string or an array.

What does this mean ? :(


it seem`s that the problem is about your column name.

check them, maybe the column names you used here differ from the table or model names.

Make like this

 if (!empty($history)) 


foreach($history as $history_1){

//update the existing record with new record

$history_1->lesson_id = $this->lesson_id; 




Hope this will work for you.

Bumping this thread as i am still stuck :huh:

@Shahcheraghean - thanks for replying. the column names are correct, so that is not the issue.

@balu - thanks for replying. your suggestion is not working - in any case there is only one row for each user_id in the database. so foreach should not be of relevance. I nverehteless tried your suggestion but the error persists

What exactly is this statement meaning ?

"Column name must be either a string or an array."

Any other suggestion would be really appreciated

hey i got this solved, it just turns out that my tbl_history did not have a primary key.

i set it right and it works great now :)

does that imply that all databases must have a primary key for any active record access ?