简体   繁体   English

未找到列:1054 'where 子句'中的未知列'id' Laravel 5.6

[英]Column not found: 1054 Unknown column 'id' in 'where clause' Laravel 5.6

I try to delete a row from my db but I can't access to it since I've not an ID colmun and 2 primary keys as you can see below:我尝试从我的数据库中删除一行,但我无法访问它,因为我没有 ID colmun 和 2 个主键,如下所示:

Trying to delete:尝试删除:

$follow = Follow::where('follower', Auth::id())->where('follows', $id)->get()->first();
$follow->delete();

My migration:我的迁移:

Schema::create('followed_by', function (Blueprint $table) {
    $table->integer('follower')->unsigned();
    $table->integer('follows')->unsigned();
    $table->foreign('follower')->references('id')->on('users');
    $table->foreign('follows')->references('id')->on('users');
    $table->primary(['follower', 'follows']);
 });

So I don't know how can I access to it since I don't know which primary key I suppose to define in my model (I've tried twice)所以我不知道如何访问它,因为我不知道我想在 model 中定义哪个主键(我已经尝试了两次)

I would strongly suggest still having an ID and use it as a primary key.我强烈建议仍然拥有一个 ID 并将其用作主键。 You can set multiple primary key in the model but it's not always working as expected.您可以在 model 中设置多个主键,但它并不总是按预期工作。 If you wish you could try to add protected $primaryKey = ['follower', 'follows'];如果您希望可以尝试添加受保护的 $primaryKey = ['follower', 'follows']; but I think you will have some other issues in the future even if this works.但我认为即使这可行,您将来也会遇到其他问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到列:1054“ where子句”中的未知列“ id”-Laravel - Column not found: 1054 Unknown column 'id' in 'where clause' - Laravel 未找到列:1054“ where子句”中的未知列“ id” - Column not found: 1054 Unknown column 'id' in 'where clause' Laravel Eloquent Update Column not found: 1054 Unknown column 'id' in 'where Clause' - Laravel Eloquent Update Column not found: 1054 Unknown column 'id' in 'where clause' 无法更新Laravel4中的记录:SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ id” - Unable to update record in Laravel4: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘id’ in ‘where clause' SQLSTATE [42S22]:找不到列:1054“ where子句” Id中的未知列“ id”为空 - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' Id is null 1054 where子句中的未知列? - 1054 Unknown column in where clause? updateOrCreate()给出未找到的列:1054“ where子句”中的未知列“ 0” - updateOrCreate() gives Column not found: 1054 Unknown column '0' in 'where clause' 找不到列:1054'on子句中的未知列'locations.id' - Column not found: 1054 Unknown column 'locations.id' in 'on clause SQLSTATE [42S22]:未找到列:1054 laravel 中“where 子句”中的未知列“3” - SQLSTATE[42S22]: Column not found: 1054 Unknown column '3' in 'where clause' in laravel laravel找不到列:1054'order子句'中的未知列'created_at' - laravel Column not found: 1054 Unknown column 'created_at' in 'order clause'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM