• 12

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Laravel 5 Migration, Invalid default value when integer

I was trying to create an table having a 0 as its default integer value The code looks like:

Schema::create('gsd_proyecto', function($table) {
        $table->string('nombre', 80)->unique();
        $table->string('descripcion', 250)->nullable();
        $table->integer('estado', 1)->default(0);
        $table->string('ultimoModifico', 35)->nullable();

But when I run the migration I'm getting the next error:

Next exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'estado' 

I was checking what is the SQL created by laravel and I found next

create table `gsd_proyecto` (
 `id` int unsigned not null auto_increment primary key, 
 `nombre` varchar(80) not null, 
 `descripcion` varchar(250) null, 
 `fechaInicio` date null, 
 `fechaFin` date null, 
 `estado` int not null default '0' auto_increment primary key,   
 `ultimoModifico` varchar(35) null, 
 `created_at` timestamp default 0 not null, 
 `updated_at` timestamp default 0 not null

As you can see, laravel is trying to set the field estado with a char value ('0') and also as an autoincrement primary key

Any help will be really appreciated

Remove the second parameter in the integer method. It sets the column as auto-increment. Check the Laravel API for more detials.


  • 16
Reply Report
      • 2
    • It worked! Thanks A lot! I was thinking in a definition like MySql does....instead I'm using tinyInteger now and it's working now. Thanks a lot!

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions