繁体   English   中英

Laravel 5.1 - 使用SQLite测试数据库在迁移时给出“没有这样的索引”错误()

[英]Laravel 5.1 - test database with SQLite gives 'no such index' error on migration down()

运行时,下面的架构构建的代码工作完全 php artisan migratephp artisan migrate:rollback 本地分期 (生产等)的环境。 这将运行alter table语句来修改现有表。

注意:由于行为空,因此无需为category_id设置nullabledefault 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');

我正在使用SQLite运行我的功能测试:memory:配置,当数据库回滚时我收到以下错误(感谢DatabaseMigrations特性)

General error: 1 no such index: stores_category_id_index (SQL: DROP INDEX stores_category_id_index)

为什么会发生这种情况,我不得不在SQLite上配置一些我不知道的东西?

默认情况下,SQLite禁用外键支持。

您需要手动启用它或使用其他数据库。

Laravel 5.1:启用SQLite外键约束

上面的链接讨论了如何执行此操作,但基本上您需要找到一种方法在测试之前在功能测试环境中运行'PRAGMA foreign_keys = 1'。

免责声明:我只在Laravel 5上试过这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM