maculus1's avatar

SQLSTATE[42S22]: Column not found: 1054 Unknown column

Hello guys, i'm working on a Lumen version 5.3 API, however I'm getting the error below.

When i try to retrieve a specific record, in my case, a specific campaign. Please note though, that i'm building this application around an existing database where the unique identifier is "campaign_id" and not "id" which is generic when using eloquent to create the table and do the migrations.

Specific error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'campaign.id' in 'where clause' (SQL: select * from campaign where campaign.id = 1 limit 1)

This error is thrown when i enter the route below: http://localhost:8000/api/campaign/1

Please see the routes defined in my web.php file:

$app->group(['prefix' => 'api/campaign'], function($app) {

$app->get('/','CampaignController@index');

$app->get('{id}','CampaignController@find');

});

Can anyone advise how i can find a specific campaign even though the unique identifier for each campaign is "campaign_id" and not "id" in my database?

0 likes
2 replies
frezno's avatar
frezno
Best Answer
Level 36

in your campaign model you have to override the standard id:

class Campaign extends Eloquent {

    protected $primaryKey = 'campaign_id';

}

1 like

Please or to participate in this conversation.