php – Laravel 5 Migration,整数时的默认值无效
发布时间:2020-12-14 19:39:43 所属栏目:大数据 来源:网络整理
导读:我试图创建一个以0作为默认整数值的表 代码如下: Schema::create('gsd_proyecto',function($table) { $table-increments('id'); $table-string('nombre',80)-unique(); $table-string('descripcion',250)-nullable(); $table-date('fechaInicio')-nullable(
我试图创建一个以0作为默认整数值的表
代码如下: 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(); }); 但是当我运行迁移时,我得到了下一个错误: Next exception 'IlluminateDatabaseQueryException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'estado' 我正在检查laravel创建的SQL是什么,然后我找到了 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 ) 正如您所看到的,laravel正在尝试使用char值(‘0’)设置字段estado,并将其作为自动增量主键 任何帮助将非常感激
删除整数方法中的第二个参数.它将列设置为自动增量.检查Laravel API以获取更多详细信息.
http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_integer $table->integer('estado')->default(0); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |