Reputation: 1674
I'm trying to add a foreign key to an existing table:
public function up()
{
Schema::table('employee', function (Blueprint $table) {
$table->uuid("agency_id");
}
}
and SQLite is throwing error:
General error: 1 Cannot add a NOT NULL column with default value NULL (SQL: alter table "employees" add column "agency_id" varchar not null)
I cannot add a default value of an empty string as the type is UUID. What can I do?
Upvotes: 1
Views: 256
Reputation: 34678
SQLite
would typically choose NULL, but you've specified it can't be NULL, so what should it be? It has no way of knowing.
When adding a table from scratch, you can specify NOT NULL
. However, you can't do this when adding a column. SQLite
's specification says you have to have a default for this.
You could specify the default value, such as :
public function up()
{
Schema::table('employee', function (Blueprint $table) {
$table->uuid("agency_id")->nullable();
}
}
Upvotes: 0