Laravel 4迁移错误 – 创建两个auto_increment主键字段

我使用此设置进行了迁移:

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

进行php工艺迁移后,会返回错误:

[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 ())

我没有将user_id指定为auto_increment主键,但是Migration将其视为.

如何在Migrations中创建外键?

最佳答案
@crynobone:第二个参数是布尔使用来确定主键,整数没有长度选项.

请参考:https://github.com/laravel/laravel/issues/2212#issuecomment-21608193

转载注明原文:Laravel 4迁移错误 – 创建两个auto_increment主键字段 - 代码日志