Laravel 4迁移错误-创建两个auto_increment主键字段 [英] Laravel 4 Migration error - creates two auto_increment primary keys fields

查看:124
本文介绍了Laravel 4迁移错误-创建两个auto_increment主键字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I made a migration with this setup:

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

在进行php artisan迁移之后,它会返回错误:

After doing php artisan migrate it returns an error:

[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会这样对待.

I didn't specify user_id to be an auto_increment primary key but Migration treats it as so.

如何在迁移中创建外键?

How can I make a foreign key in Migrations?

推荐答案

@crynobone:第二个参数是布尔值,用于确定主键,而整数则没有长度选项.

@crynobone: Second parameter are for boolean use to determine primary key, there no length option for integer.

在这里参考: https://github.com/laravel/laravel/issues/2212#issuecomment- 21608193

这篇关于Laravel 4迁移错误-创建两个auto_increment主键字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆