【发布时间】:2015-07-31 11:06:28
【问题描述】:
我试图创建一个具有 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 'Illuminate\Database\QueryException' 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 正在尝试将字段 estado 设置为 char 值 ('0') 并作为自动增量主键
任何帮助将不胜感激
【问题讨论】:
标签: php migration schema laravel-5 builder