TobiasS's avatar
Level 10

Sqlite test database do not update when added columns

Hi!

I have added a column, and changed one columnname in a new migration. I'm running Postgres.

For my test I use Sqlite.

 Schema::table('log_services', function (Blueprint $table) {
            $table->date('end')->nullable();
            $table->renameColumn('date', 'start');
        });

The new migration look like above

I get the following errormessage

SQLSTATE[HY000]: General error: 1 table log_services has no column named end (SQL: insert into "log_services" ("title", "start", "end", "user_id", "updated_at", "created_at")

The code works without a problem on local env using postgres, but test fails in sqlite

Any advice?

0 likes
5 replies
Sergiu17's avatar

Hi, did you add DatabaseMigrations to your test?

use Illuminate\Foundation\Testing\DatabaseMigrations;

use DatabaseMigrations;
TobiasS's avatar
Level 10

Hi!

If I add the DatabaseMigration I get the following error

database/migrations/2020_02_10_103035_create_logbooks_table.php:31
      Illuminate\Support\Facades\Facade::__callStatic("dropIfExists")

  • Tests\Feature\LogServiceTest > it can show logservice
   Illuminate\Database\QueryException 

  SQLSTATE[HY000]: General error: 1 no such table: main.logcontents (SQL: drop table if exists "logbooks")

If I comment out the down-method in the migration the error goes away, and I get the same error as above again

SQLSTATE[HY000]: General error: 1 table log_services has no column named end (SQL: insert into "log_services" ("title", "start", "end", "user_id", "updated_at", "created_at")
TobiasS's avatar
TobiasS
OP
Best Answer
Level 10

Problem solved by creating two new migrations

one with

 $table->date('end')->nullable();

and one with

   $table->renameColumn('date', 'start');

From Laravel documentation https://laravel.com/docs/8.x/migrations

Dropping or modifying multiple columns within a single migration while using an SQLite database is not supported.

6 likes
ahinkle's avatar

@TobiasS Wow, experienced this today. What a weird quirk with SQLite. Thanks so much!

mic2100's avatar

Thanks for this... I found I was having the same issues with SQLite when one migration was adding a new column and dropping some others, the SQLite table seemed to just be dropping the columns and not adding the other. Separating them out into different migrations resolved this issue.

Please or to participate in this conversation.