Laravel 5 Migration, Invalid default value when integer

I tried to create a table with 0 as the default value. The code looks like this:

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

But when I start the migration, I get the following error:

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

I checked what SQL created by laravel is and I found the following

 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 estado field with a char value ( '0' ), and also as a primary auto-increment key

Any help would be really appreciated

+6
source share
1 answer

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

http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_integer

 $table->integer('estado')->default(0); 
+12
source

Source: https://habr.com/ru/post/987506/


All Articles