Laravel 4-Artisan错误SQLSTATE [42000] [英] Laravel 4 - Artisan error SQLSTATE[42000]
问题描述
我正在尝试为用户表创建一个新的迁移,我具有以下架构:
I am trying to create a new migration for my users table, I have the following schema:
Schema::create('users', function($t) {
$t->increments('id');
$t->string('username', 16);
$t->string('password', 64);
$t->integer('role', 64);
$t->timestamps();
});
当我尝试从终端运行php artisan migration时,出现以下错误:
When I try to run php artisan migrate from the terminal, I get the following error:
[异常]
SQLSTATE [42000]:语法错误或访问冲突:1075错误 表定义;只能有一个自动列,它必须 定义为键(SQL:创建表users
(id
int unsigne d auto_increment主键不为空,username
varchar(16)不为空,password
varchar(64)否t null,role
int不为null auto_increment主键,created_at
时间戳默认为0,不为null ,updated_at
时间戳默认为0不为null))(绑定:数组(
))
[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 tableusers
(id
int unsigne d not null auto_increment primary key,username
varchar(16) not null,password
varchar(64) no t null,role
int not null auto_increment primary key,created_at
timestamp default 0 not null ,updated_at
timestamp default 0 not null)) (Bindings: array (
))
该错误与角色"字段有关,因为将其删除似乎运行良好.
The error has something to do with the 'role' field, as when this is removed it seems to run fine.
在此先感谢您的帮助或见解.
Thanks in advance for any help or insight.
推荐答案
integer
的第二个参数是自动递增标志.
The second parameter for integer
is an auto increment flag.
public function integer($column, $autoIncrement = false, $unsigned = false)
https://github .com/laravel/framework/blob/5.4/src/Illuminate/Database/Schema/Blueprint.php#L510
这篇关于Laravel 4-Artisan错误SQLSTATE [42000]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!