我犯了一個移民與此設置: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