我正在尝试向现有表添加外键:
public function up()
{
Schema::table('employee', function (Blueprint $table) {
$table->uuid("agency_id");
}
}
并且SQLite抛出错误:
一般错误:1无法添加具有默认值NULL的NOT NULL列(SQL:alter table“ employees”添加列“ agency_id” varchar不为null)
由于类型为UUID,因此无法添加空字符串的默认值。我能做什么?
答案 0 :(得分:0)
SQLite
通常会选择NULL,但是您已指定它不能为NULL,那么应该是什么呢?它无法知道。
从头开始添加表时,可以指定NOT NULL
。但是,添加列时无法执行此操作。 SQLite
的规范说,您必须为此设置默认值。
您可以指定默认值,例如:
public function up()
{
Schema::table('employee', function (Blueprint $table) {
$table->uuid("agency_id")->nullable();
}
}