简体   繁体   中英

Is having an "id" column in a table mandatory to work with BackPack?

I have a table with columns color_id and list_id . When I load a page with that specific model in Laravel BackPack, it throws an error:

SQLSTATE[42703]: Undefined column: 7 ERROR: column "id" does not exist LINE 1: select * from "color_list" order by "id" desc l... ^ (SQL: select * from "color_list" order by "id" desc limit 10)

In general, this is correct. I do not have an id column since it's a pivot table. I assumed adding custom sorting would solve the problem so I added the following line in my controller's setup() method:

$this->crud->addClause('orderBy', 'color_id', 'DESC');

This didn't solve the problem and BackPack is still trying to search id column.

SQLSTATE[42703]: Undefined column: 7 ERROR: column "id" does not exist LINE 1: ...color_list" order by "color_id" desc, "id" desc ... ^ (SQL: select * from "color_list" order by "color_id" desc, "id" desc limit 10)

Is there no way around it? Do I really need to add an id column to my table?

By adding this to my model, I was able to solve it for the moment:

protected $primaryKey = 'color_id';

But is this really the only solution?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM