Laravel 4 Migration error – creates two auto_increment primary keys fields

database-migrationlaravellaravel-4

I made a migration with this setup:

$table->increments('id');
$table->integer('user_id', 10)->unsigned(); // this is meant to be used as a foreign key

After doing php artisan migrate it returns an error:

[Exception]                                                                                                                                                                                 
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition;
there can be only one auto column and it must be defined as a key (SQL: create table `transactions` (`id` int unsigned not null auto_increment primary key, `user_id` int unsigned not null auto_increment primary key) default character set utf8 collate utf8_unicode_ci) (Bindings: array ())

I didn't specify user_id to be an auto_increment primary key but Migration treats it as so.

How can I make a foreign key in Migrations?

Best Answer

@crynobone: Second parameter are for boolean use to determine primary key, there no length option for integer.

Refer here: https://github.com/laravel/laravel/issues/2212#issuecomment-21608193

Related Topic