Mysql - Table does not have Primary Key

Dear All,

I try to use YII for develop application, but when i follow manual "Building a Blog System using Yii' i have difficult because when i execute command crud table i have error Table does not have Primary Key.

My env is:

  • Apache 2.2

  • Php 5.2.6

  • YII 1.0.4

  • Mysql 5

Regards,

Samsun

The crud command requires primary key to be defined in your tables. If you are working with legacy tables and can't specify primary key, you can declare it in primaryKey() method of your model class.

I have the same problem.

mysql 5

php 5.2.4

Where is my table or DB is legacy? "id" is primary key.

desc User;

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

| Field    | Type         | Null | Key | Default | Extra          |

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

| id       | int(11)      | NO   | PRI | NULL    | auto_increment |

| username | varchar(128) | NO   |     |         |                |

| password | varchar(128) | NO   |     |         |                |

| email    | varchar(128) | NO   |     |         |                |

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

I have override method primaryKey in protected/models/User.php and all works fine

public function primaryKey()

{

return 'id';

}

how should configure when my table have multiple fields in primery key???

sorry for my english

Return an array of them.

samsun: did you definitely make the tables according to the schema found in the protected/data/ directory ? Looks like they are missing PK.