foreign key cannot be found in the database [Resolved]

I am following the book to chapter6, page 123

I got this error when I try to create an issue (http://localhost/trackstar/index.php?r=issue/create&pid=1)

CDbException

The relation "users" in active record class "Project" is not specified correctly: the join table "tbl_project_ user_assignment" given in the foreign key cannot be found in the database.

/var/www/html/trackstar/protected/models/Project.php(36), which is pointing this line

$usersArray = CHtml::listData($this->users, ‘id’, ‘username’);

Any ideas why I got error on this?

I am using mysql 5.5, here is mysql info,

mysql> select version();

±----------+

| version() |

±----------+

| 5.5.10 |

±----------+

mysql> show create table tbl_project_user_assignment\G

*************************** 1. row ***************************

   Table: tbl_project_user_assignment

Create Table: CREATE TABLE tbl_project_user_assignment (

project_id int(11) NOT NULL,

user_id int(11) NOT NULL,

create_time datetime DEFAULT NULL,

create_user_id int(11) DEFAULT NULL,

update_time datetime DEFAULT NULL,

update_user_id int(11) DEFAULT NULL,

PRIMARY KEY (project_id,user_id),

KEY FK_user_project (user_id),

CONSTRAINT FK_project_user FOREIGN KEY (project_id) REFERENCES tbl_project (id) ON DELETE CASCADE,

CONSTRAINT FK_user_project FOREIGN KEY (user_id) REFERENCES tbl_user (id) ON DELETE CASCADE

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1 row in set (0.00 sec)

Thanks!

Can you provide User and Project model classes(just relationship method), I think problem in in relationship definitions.

Thanks Ivica, here is the code

User:




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', 'requester_id'),

		'issues1' => array(self::HAS_MANY, 'Issue', 'owner_id'),

		'tblProjects' => array(self::MANY_MANY, 'Project', 'tbl_project_user_assignment(user_id, project_id)'),

	);

}



Project:




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

		);

	}



User model was generated by Gii, Project model I copied from the book. Thanks!

You are exactly right! "tbl_project_user_assignment" has an extra space in my original code! For some reason my editor did not catch it. Thanks so much!