我有以下迁移,我在表格中添加了一个额外的列:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddTenantIdToPeopleTable extends Migration
{
public function up()
{
/*
* Need to create the column as null and then mark it as non-null to
* avoid SQLite problem General error: 1 Can not add to NOT NULL column with default value NULL
*/
Schema::table('people', function (Blueprint $table) {
$table->integer('tenant_id')->nullable()->unsigned();
$table->index('tenant_id');
});
Schema::table('people', function (Blueprint $table) {
$table->integer('tenant_id')->nullable(false)->change();
});
}
public function down()
{
Schema::disableForeignKeyConstraints();
Schema::table('people', function (Blueprint $table) {
$table->dropColumn('tenant_id');
});
Schema::enableForeignKeyConstraints();
}
}
我可以使用PostgreSQL,SQLite和MySQL运行此迁移而没有任何错误,但是当我尝试使用Maria DB运行时,会发生以下错误:
我尝试了一些东西,但没有任何作用。
答案 0 :(得分:0)
我设法让这件事发挥作用。 我刚刚添加了&#34; - &gt;默认(null)&#34;
我这样做了:
public function up()
{
Schema::table('people', function (Blueprint $table) {
$table->integer('tenant_id')->nullable()->unsigned();
$table->index('tenant_id');
});
Schema::table('people', function (Blueprint $table) {
$table->integer('tenant_id')->nullable(false)->default(null)->change();
});
}