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
source share