我犯了一个移民与此设置: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将其视为如此。
如何在迁移中创建外键?
那么你如何处理外键? – jrenouard
nvm,在这里找到答案http://stackoverflow.com/questions/22077573/laravel-migration-will-not-add-foreign-key你应该使用$ table-> integer('app_group_id') - > length(10 ) - >无符号();在Laravel 4 – jrenouard