【发布时间】:2018-09-18 07:19:26
【问题描述】:
我有以下迁移,我在表中添加了一个额外的列:
<?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 运行时,会发生此错误:
我尝试了一些东西,但没有任何效果。
【问题讨论】:
-
您已经在
NULL列中获得了现有数据。如果您没有nullable列,Maria DB 不想要NULL值。有什么理由不希望它可以为空? -
没有特别的原因。我设法用 postgres、mysql 和 sqlite 做到这一点,但 mariaDB 让我很难过。有什么办法可以做到吗?
标签: mysql laravel laravel-5 migration mariadb