From 109940c0021febbe9a897bccdaf94a56039b7717 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Fri, 1 Apr 2022 16:28:06 +0200 Subject: [PATCH] Fix sqlite 'not null error' during alter table migration --- ...t_twofaccounts_uri_in_multiple_columns.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php b/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php index 77e041d1..be19fc5c 100644 --- a/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php +++ b/database/migrations/2021_09_08_191139_split_twofaccounts_uri_in_multiple_columns.php @@ -16,11 +16,20 @@ class SplitTwofaccountsUriInMultipleColumns extends Migration */ public function up() { - Schema::table('twofaccounts', function (Blueprint $table) { - $table->string('otp_type', 10); - $table->text('secret'); - $table->string('algorithm', 20); - $table->unsignedTinyInteger('digits'); + $driver = Schema::connection($this->getConnection())->getConnection()->getDriverName(); + + Schema::table('twofaccounts', function (Blueprint $table) use ($driver) { + if ('sqlite' === $driver) { + $table->string('otp_type', 10)->default(''); + $table->text('secret')->default(''); + $table->string('algorithm', 20)->default(''); + $table->unsignedTinyInteger('digits')->default(6); + } else { + $table->string('otp_type', 10); + $table->text('secret'); + $table->string('algorithm', 20); + $table->unsignedTinyInteger('digits'); + } $table->unsignedInteger('period')->nullable(); $table->unsignedBigInteger('counter')->nullable(); });