小编San*_*ruz的帖子

Laravel 4 Migration错误 - 创建两个auto_increment主键字段

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

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

做了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 ())
Run Code Online (Sandbox Code Playgroud)

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

如何在迁移中创建外键?

database-migration laravel laravel-4

11
推荐指数
1
解决办法
7643
查看次数

标签 统计

database-migration ×1

laravel ×1

laravel-4 ×1