我有一个带有MySQL数据库的Laravel项目,我的迁移工作非常好,但我的问题是,当我将MySQL连接更改为SQLite并运行迁移时,对于没有默认值的字段,会出现一个错误。解决这个问题的办法是什么?我发现这个解决方案很脏,我不得不将这个条件添加到许多迁移中。
$driver = Schema::connection($this->getConnection())
->getConnection()->getDriverName();
Schema::table('proposals', function (Blueprint $table) use ($driver) {
if ($driver === 'sqlite') {
$table->unsignedBigInteger('final_amount')->default('');
} else {
$table->unsignedBigInteger('final_amount');
}
});误差
SQLSTATEHY000:一般错误:1不能添加默认值为NULL
的非空列
发布于 2022-05-01 13:30:53
如果要在现有表中添加带有项的新列,请设置有效的默认值或将其设置为可空。
$driver = Schema::connection($this->getConnection())->getConnection()->getDriverName();
Schema::table('proposals', function (Blueprint $table) use ($driver){
if ($driver === 'sqlite'){
$table->unsignedBigInteger('final_amount')->default(0);
}else{
$table->unsignedBigInteger('final_amount')->nullable();
}
});https://stackoverflow.com/questions/72076780
复制相似问题