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

在发生这种情况的线路上,我有这样的代码:

$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'
    ]);

如果我把"开始月份"这行注释掉,那么它在逻辑上是有效的.

在单元测试的设置中,我运行了所有迁移(大约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);

这会将所有迁移列为已完成.我使用内存中的sqlite db进行测试.

我想知道迁移是否是异步运行的,在我的代码运行时它们还没有全部完成?或者如果迁移在某个地方悄silent息地失败了?

我已经干了几个小时了,不知道发生了什么事.

*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.

推荐答案

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');
});

Laravel相关问答推荐

Hostinger Laravel网站未显示错误

在GitHub操作中缺少PHPStan和PHPMD输出,但在本地存在

Livewire 3软件包开发

Uncaught ReferenceError:未定义require[Shopify PHP React Browser问题]

Laravel 获取具有多对多关系的中间表数据

Laravel + Plupload 上传到 S3 响应以进行预检无效 - CORS

调用未定义函数 Illuminate\Encryption\openssl_decrypt()

Laravel 5.1 如何在Blade 文件上使用 {{ old('') }} 助手进行无线电输入

Laravel 5.x 中 onUpdate / onDelete 的可用操作

Laravel Eloquent Pluck 不丢失密钥

如何从 laravel 中的现有数据库创建迁移

用于集合的 Laravel 5.5 API 资源

laravel 队列 - 同步驱动程序如何工作?它是在单独的进程/线程还是主执行线程中执行?

laravel 如何读取 app/config/app.php 调试变量

Laravel/PHPUnit:断言 json 元素存在而不定义值

Laravel 5.4 - Mix - 如何运行浏览器实时重新加载

[Vue 警告]:找不到元素:#app

Laravel 5 - 跳过迁移

如何在 Laravel 中动态更改 .env 文件中的变量?

laravel中的动态网址?