prajwal_stha
prajwal_stha

Reputation: 377

Primary key in Laravel model not working

I am developing an application in Laravel 5.2.27. I have setup a model where primary key is other than id and I have defined primary key in my model by using:

protected $primaryKey = 'district_code';

When fetching the records the value of district code is displayed something else, different than that of record stored in database. But when I remove the line protected $primaryKey = 'district_code'; everything works fine.

Upvotes: 2

Views: 1711

Answers (2)

rebduvid
rebduvid

Reputation: 1144

Try to add in the model

public $incrementing = false;

Upvotes: 3

Qazi
Qazi

Reputation: 5135

can you show/add your Table structure and Records which you are fetching?

another thing, did you defined table name in your model? eg like this.

protected $table    =   'doseage_form';

Upvotes: 0

Related Questions