Hi,
I have a table without primary key and when I try to create crud with the model of that table it shows Error: Table "test" does not have a primary key.
Is this a bug in Yii??
Hi,
I have a table without primary key and when I try to create crud with the model of that table it shows Error: Table "test" does not have a primary key.
Is this a bug in Yii??
Why would you ever make a table without a primary key ?.
Except for joiner tables, where you dont need to create a separate model, i think primary key should be included in the table for indexing and to differentiate between two similar records.
Even if the table does not explicitly require a primary key, i would still add a surrogate primary key.
This is what i have been taught to do and this makes sense.
Can you tell by example, why your db table does not or should not have a primary key ?
crud generator doesn’t support tables with no primary key or with composite primary keys but you can declare a primary key in your model like following:
public function primaryKey()
{
return 'columnName';
}
What will happen if i need to create a view not a table and also I need a crud for it.Then this would be a matter.Anyway got a solution for this by creating a primary key function in my model…
public function primaryKey()
{
return 'id';
}
Yeap bro…this is working…actually any name as columnName
and I meant any column name by columnName
Sorry I meant it dosen’t need to be a field name of table.By defining a new property in model you can do that.
no problem bro, you’re right