doulang7699 2016-05-19 21:15 采纳率: 0%
浏览 101

Laravel删除没有'id'的行

I'm using laravel to create a small app. This app uses a remote database. This database doesn't have an AI id. So when I try to delete a row from the datbase (which I selected with the 'where::' function) I get the following error:

Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: delete from `mailbox` where `id` is null)

Is there a possibility to delete a row with using another key than the primary id?

  • 写回答

2条回答 默认 最新

  • duandingyou3331 2016-05-19 21:26
    关注

    If you have primary key, set in your model with

    public $primary = 'my_PK';
    

    If you don't have any PK, use a custom query:

    $q = 'DELETE FROM my_table where my_field = ?'
    \DB::delete($q, [$my_data]);
    
    评论

报告相同问题?