作者:牛尾巴2010 | 来源:互联网 | 2023-02-12 11:46
我的单元测试最近开始失败.我收到此错误:
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 db进行测试.
我想知道迁移是否是异步运行的,并且在我的代码运行时它们都没有完成?或者,如果迁移在某处静默失败?
我已经在这几个小时了,不知道发生了什么.
*更新我有一个在上述迁移后运行的迁移,我确认后续迁移成功.因此,正是这一次迁移以某种方式无声地失败.
1> ajon..:
我发现了这个问题.这是因为SQLite的有没有多添加列报表中一个表调用所看到的可笑限制在这里.
当我将迁移分离出来时,它起作用:
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');
});