phplaravelsqlitedatabase-migration

Laravel table * has no column named *


My unit tests recently started failing. I am getting this error:

PDOException: SQLSTATE[HY000]: 
General error: 1 table loan_details has no column named start_month

The line where it is happening, I have this code:

$loan = LoanDetails::create(['loan_percentage' => .8,
        'loan_product_id' => 1,
        'interest_rate' => .5,
        'start_month' => 0,
        'term' => 120,
        'fixed_finance_fee' => 0,
        'variable_finance_Fee' => 0,
        'valid_from' => '2015-01-01'
    ]);

If I comment out the "start_month" line then it logically works.

In the setup of my unit tests I run all migrations (about 80).

I have a migration that looks like this:

Schema::table('loan_details', function(Blueprint $table){
     $table->integer('start_month')->unsigned()->after('interest_only')->default(0);
     $table->decimal('balloon_percent',4,3)->after('term')->nullable();
     $table->integer('balloon_month')->after('balloon_percent')->nullable();
     $table->dropColumn('ordinal_rank');
});

So, I wondered if all the migrations weren't running so I ran this code:

$rows = DB::table('migrations')->get();
print_r($rows);

This lists all of the migrations as having completed. I am using an in memory sqlite db for the tests.

I am wondering if the migrations are run asynchronously and they aren't all finished by the time my code runs? Or if the migrations are silently failing somewhere?

I've been at this for hours and don't know what is happening.

*UPDATE I have a migration that runs AFTER the above migration, and I confirmed that the subsequent migration was successful. So it is just this one migration that is silently failing in some way.


Solution

  • I found the issue. It is because of the ridiculous limitation that sqlite has of not having multiple add column statements in one table call as seen here.

    When I separate out the migration as below it works:

    Schema::table('loan_details', function(Blueprint $table){
        $table->integer('start_month')->unsigned()->after('interest_only')->default(0);
    });
    Schema::table('loan_details', function(Blueprint $table){
        $table->decimal('balloon_percent',4,3)->after('term')->nullable();
    });
    Schema::table('loan_details', function(Blueprint $table){
        $table->integer('balloon_month')->after('balloon_percent')->nullable();
    });
    Schema::table('loan_details', function(Blueprint $table){
        $table->dropColumn('ordinal_rank');
    });