我使用了以下这个设置进行了迁移:
$table->increments('id');
$table->integer('user_id', 10)->unsigned(); // this is meant to be used as a foreign key
在运行 php artisan migrate 后,返回一个错误:
[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指定为自增主键,但迁移(Migration)似乎把它当作了自增主键。
在迁移中如何创建外键?