をデフォルトの整数値として持つテーブルを作成しようとしました。コードは次のようになります。
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')で、また自動インクリメントとして主キー
どんな助けでも本当にありがたいです
integer
メソッドの2番目のパラメーターを削除します。列を自動インクリメントとして設定します。その他の詳細については、Laravel APIを確認してください。
http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_integer
$table->integer('estado')->default(0);