违反完整性约束:如何连接两个表

Csa*_*aaa 5 php mysql join

我正在为 laravel 的一个学校项目制作一个程序,所以我尝试加入两个表:产品和目的地

表 Product 有以下列:id、name

Destinations 表包含以下列:Destinations:id,product_id,destination,quantity,target_person

我需要加入product_idid

products = DB::table('products')
    ->leftJoin('destinations','id','=','destinations.product_id ')
    ->get();
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用时LEFT JOIN,出现以下错误:

SQLSTATE[23000]:违反完整性约束:1052 on 子句中的列 'id' 不明确(SQL:select * from productsinner join destinationson id= destinations. product_id

Bil*_*med 5

使用表参考 products.id

products = DB::table('products')
    ->leftJoin('destinations','products.id','=','destinations.product_id')
    ->get();
Run Code Online (Sandbox Code Playgroud)