[英]Laravel 5.1 - test database with SQLite gives 'no such index' error on migration down()
The following schema builder code works perfectly when running php artisan migrate
and php artisan migrate:rollback
on local and staging (production-like) environment. 运行时,下面的架构构建的代码工作完全
php artisan migrate
和php artisan migrate:rollback
本地和分期 (生产等)的环境。 This will run an alter table
statement to modify an existing table. 这将运行
alter table
语句来修改现有表。
Note: since rows are empty, there is no need to set nullable
or default value
to the category_id
: 注意:由于行为空,因此无需为
category_id
设置nullable
或default value
:
// up
$table->integer('category_id')->unsigned()->index();
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
// down
$table->dropForeign('stores_category_id_foreign');
$table->dropColumn('category_id');
I'm running my functional tests with SQLite using :memory:
configuration, and I'm getting the following error when the database rolls back (thanks to the DatabaseMigrations
trait) 我正在使用SQLite运行我的功能测试
:memory:
配置,当数据库回滚时我收到以下错误(感谢DatabaseMigrations
特性)
General error: 1 no such index: stores_category_id_index (SQL: DROP INDEX stores_category_id_index)
Why is this happening, is there something I have to configure on SQLite that I don't know of? 为什么会发生这种情况,我不得不在SQLite上配置一些我不知道的东西?
By default SQLite has foreign key support disabled. 默认情况下,SQLite禁用外键支持。
You'll need to enabled it manually or use a different DB. 您需要手动启用它或使用其他数据库。
Laravel 5.1: Enable SQLite foreign key constraints Laravel 5.1:启用SQLite外键约束
Link above talks about how to do this but essentially you need to find a way to run 'PRAGMA foreign_keys=1' on your functional test environment before tests. 上面的链接讨论了如何执行此操作,但基本上您需要找到一种方法在测试之前在功能测试环境中运行'PRAGMA foreign_keys = 1'。
Disclaimer: I've only tried this on Laravel 5 免责声明:我只在Laravel 5上试过这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.