无法使用laravel migrtions重命名日期时间列

5ssjco0h  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(206)

我想简单地重命名我的一列,尽管它一直在说

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'sendReminderCouple48' (SQL: ALTER TABLE sendIntakes CHANGE sendReminderCouple36 sendReminderCouple48 DATETIME DE  
  FAULT 'NULL')

目前是 sendReminderCouple36 - DATETIME - NULLABLE 我只想把它改名为 sendReminderCouple48 ```
public function up()
{
Schema::table('sendIntakes', function (Blueprint $table) {
$table->renameColumn('sendReminderCouple36', 'sendReminderCouple48');
});
}

public function down()
{
Schema::table('sendIntakes', function (Blueprint $table) {
$table->renameColumn('sendReminderCouple48', 'sendReminderCouple36');
});
}

注意:我不想在配置文件中做任何严格的更改。
f2uvfpb9

f2uvfpb91#

我通过将类型更改为文本-重命名-然后返回到日期时间来修复它

public function up()
{
    Schema::table('sendIntakes', function (Blueprint $table) {
        $table->text('sendReminderCouple36')->default(null)->nullable()->change();
    });

    Schema::table('sendIntakes', function (Blueprint $table) {
        $table->renameColumn('sendReminderCouple36', 'sendReminderCouple48');
    });

    Schema::table('sendIntakes', function (Blueprint $table) {
        $table->datetime('sendReminderCouple48')->default(null)->nullable()->change();
    });
}

    public function down()
    {
        Schema::table('sendIntakes', function (Blueprint $table) {
            $table->text('sendReminderCouple48')->default(null)->nullable()->change();
        });

        Schema::table('sendIntakes', function (Blueprint $table) {
            $table->renameColumn('sendReminderCouple48', 'sendReminderCouple36');
        });

        Schema::table('sendIntakes', function (Blueprint $table) {
            $table->datetime('sendReminderCouple36')->default(null)->nullable()->change();
        });
    }
cxfofazt

cxfofazt2#

这可能与laravel框架上的问题22050有关。你正在运行mariadb作为你的数据库引擎吗?
按照线程中的建议,在执行重命名调用之前,可以尝试更改列的默认值:

Schema::table('products', function (Blueprint $table) {
    $table->string('name')->default(null)->change();
});
Schema::table('products', function (Blueprint $table) {
    $table->renameColumn('name', 'description');
});
Schema::table('products', function (Blueprint $table) {
    $table->string('description')->default(null)->change();
});

相关问题