gwa's avatar
Level 3

Homestead sqlite timestamp non-contant default

Hi

I run my integration tests with

'sqlite_testing' => [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ],

and use the

use DatabaseMigrations; 

Trait. Until now everything was fine. Today i tried to add a timestamp column to an existing table.

Schema::table('mytablename', function ($table) {
            $table->timestamp('mycolumnname')->useCurrent();
});

In my Homestead mySQL everything is OK but my Test fail with

Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 Cannot add a column with non-constant default (SQL: alter table "mytablename" add column "mycolumnname" datetime not null default CURRENT_TIMESTAMP)

Any Idea how to fix this? Its annoying to spent a lot of time to fix "not real" problems :(

Thanks!

Max

0 likes
4 replies
gwa's avatar
Level 3

Sure but I think the Problem is in the migration. What I know until now is that sqlite needs a default value if its not nullable. For the Timestamp I use ->useCurrent() for default and thats working with mySQL but as it seem not with sqlite. I also tried ->default(DB::raw('CURRENT_TIMESTAMP')) with same result.

public function test_a_standard_user_should_not_see_company()
    {
        $user = factory(App\User::class)->create();
        $team = factory(App\Team::class)->create();
        $user->teams()->attach($team, ['role' => 'member']);

        $this->actingAs($user)
            ->visit('/company')
            ->seePageIs('/home');
    }
gwa's avatar
Level 3

@ifpingram Thanks a lot for your Help!

I fixed it now with a

$table->timestamp('start')->default(0);

This is not optimal for me but works in this case.

Please or to participate in this conversation.