SQLite needs default for altering migrations

2 minute read

March 8, 2018

When I was adding a new column to

Today I was trying to add a new column to my users table named one_click and I ran into the issue that when I ran the following test I ran into this error: General error: 1 table users has no column named one_click.

Test:

/** @test */
public function can_see_if_user_has_one_click_enabled()
{
  $paymentGateway = new FakePaymentGateway;
  $this->app->instance(PaymentGateway::class, $paymentGateway);

  $userA = factory(User::class)->create([
    'customer_id' => $paymentGateway->createCustomer('janedoe@gmail.com', $paymentGateway->getValidTestToken('4242424242424242')),
    'one_click' => false,
  ]);
  $userB = factory(User::class)->create(['customer_id' => null, 'one_click' => true]);
  $userC = factory(User::class)->create([
    'customer_id' => $paymentGateway->createCustomer('jaxdoe@gmail.com', $paymentGateway->getValidTestToken('4242424242424242')),
    'one_click' => true,
  ]);

  $this->assertFalse($userA->canOneClick());
  $this->assertFalse($userB->canOneClick());
  $this->assertTrue($userC->canOneClick());
}

Migration:

Schema::table('users', function (Blueprint $table) {
    $table->boolean('one_click')->after('customer_id');
});

I had no problem when running php artisan migrate, so the issue must have been with my testing environment. First I tried dumping my composer autoloader (composer dumpautoload), then I tried composer update with no success.

Eventually I did turn to google though I didn't really know what to search... I ended up searching "table has no column named laravel" and landed on this post: StackOverflow. While this didn't help my specific issue, it did give me an idea. Maybe the column needed a default value.

I added ->default(0) to the migration and that did the trick! Not sure why, but I'm not complaining.

Laravel sqlite tdd

Looking for more?

WIP: Laracon 2018

Laracon was this past week and it was amazing! Last night I tweeted this out:

I don't know where to begin, or how to fit everything I'm feeling into a tweet, but...

Jul 27, 2018

2 minute read

My Work Spotify Playlists

Here's a list of playlists I rotate through when I need get down to business.

  • Deep Work created by Chris Gmyr
  • Deep House Relax created by Spotify
  • mint...

May 14, 2018

1 minute read