morne
morne

Reputation: 4189

laravel 5 primary key column not named id

Im trying to migrate our current application over to Laravel-5.
This app has quite a big structure with many tables, but way less than half of the tables has a primary key called id.
Is this a problem or can you manualy specify what you want your primary key to be called.
Its just that from the training videos I am doing, it seems like no.

Upvotes: 3

Views: 5047

Answers (3)

sadalsuud
sadalsuud

Reputation: 479

$table->string('your_primary_key', 32)->primary();

'your_primary_key' is the name's primary key

32 is length

I try and it work

Upvotes: 0

Sameer Shaikh
Sameer Shaikh

Reputation: 7814

You can use

protected $primaryKey = 'Your_Primary_key';

In the Models.

Upvotes: 8

Michael Pittino
Michael Pittino

Reputation: 2178

Sure, just add $table->primary('field') to your database shema as mentioned here: http://laravel.com/docs/5.0/schema#adding-indexes

Upvotes: 1

Related Questions