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->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 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.
http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_integer
$table->integer('estado')->default(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With