我的单元测试最近开始失败。我收到此错误:
PDOException: SQLSTATE[HY000]:
General error: 1 table loan_details has no column named start_month
它发生的那一行,我有这段代码:
$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'
]);
如果我注释掉“start_month”行,那么它在逻辑上是有效的。
在我的单元测试设置中,我运行了所有迁移(大约 80 个)。
我有一个看起来像这样的迁移:
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');
});
所以,我想知道是否所有的迁移都没有运行,所以我运行了这段代码:
$rows = DB::table('migrations')->get();
print_r($rows);
这列出了所有已完成的迁移。我正在使用内存中的 sqlite 数据库进行测试。
我想知道迁移是否异步运行,并且在我的代码运行时它们还没有全部完成?或者如果迁移在某处悄无声息地失败了?
我已经在这里待了几个小时,但不知道发生了什么。
*UPDATE 我有一个迁移在上述迁移之后运行,我确认后续迁移成功。因此,只有这一迁移以某种方式悄无声息地失败了。
最佳答案
我发现了问题。这是因为 sqlite 在一个表调用中没有多个添加列语句的荒谬限制,如 here 所示。 .
当我如下分离出迁移时,它起作用了:
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');
});
关于php - Laravel 表 * 没有名为 * 的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42165587/