Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Artisan error SQLSTATE[42000]

Tags:

php

laravel

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();
    });

When I try to run php artisan migrate from the terminal, I get the following 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 users (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.

like image 564
ChrisBratherton Avatar asked Feb 18 '13 08:02

ChrisBratherton


1 Answers

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

like image 70
Robbo Avatar answered Sep 28 '22 03:09

Robbo