SQLSTATE [42000]:语法错误或访问冲突:1067'fechaNacimiento'的默认值无效-laravel

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQLSTATE [42000]:语法错误或访问冲突:1067'fechaNacimiento'的默认值无效-laravel相关的知识,希望对你有一定的参考价值。

执行迁移时发生错误

enter image description here

移民:

<?php

use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class MakeSomeColumnsNullableToPacientesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('pacientes', function (Blueprint $table) {
            $table->integer('obra_social_id')->unsigned()->nullable()->change();
            $table->integer('plan_id')->unsigned()->nullable()->change();

            $table->integer('pais_id')->unsigned()->nullable()->change();
            $table->integer('provincia_id')->unsigned()->nullable()->change();
            $table->integer('localidad_id')->unsigned()->nullable()->change();

            $table->date('fechaNacimiento')->nullable()->change();
            $table->string('telefono', 25)->nullable()->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('pacientes', function (Blueprint $table) {
            $table->integer('obra_social_id')->unsigned()->change();
            $table->integer('plan_id')->unsigned()->change();
        });
    }
}




帮助请由于此错误,它使我无法很好地执行迁移

fechaNacimiento == 出生日期

原始表格:$ table-> date('fechaNacimiento');

答案

尝试为您的列设置默认值:

$table->date('fechaNacimiento')->nullable()->default(NULL)->change();

或:

 $table->date('fechaNacimiento')->nullable()->default('DEFAULT')->change();

以上是关于SQLSTATE [42000]:语法错误或访问冲突:1067'fechaNacimiento'的默认值无效-laravel的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 5.8 SQLSTATE [42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误

SQLSTATE [42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误 - LARAVEL

Cakephp SQLSTATE [42000]:语法错误或访问冲突:1064

带有消息“SQLSTATE [42000]”的未捕获异常“PDOException”:语法错误或访问冲突:

SQLSTATE [42000]:语法错误或访问冲突:1064 PHP/MySQL [关闭]

为啥我是 laravel 抛出 SQLSTATE[42000]:语法错误或访问冲突:1064 错误