YII Primary Key error

Error: Table “user” does not have a primary key.

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.

override method primaryKey in protected/models/User.php
public function primaryKey()
return ‘id’;


Permanent link to this article: https://blog.openshell.in/2012/04/yii-primary-key-error/

Leave a Reply

Your email address will not be published.