Laravel 5.1 - 使用 SQLite 的测试数据库在向下迁移时出现 'no such index' 错误()
Laravel 5.1 - test database with SQLite gives 'no such index' error on migration down()
当 运行ning php artisan migrate
和 php artisan migrate:rollback
在 local[=35 上时,以下架构构建器代码 完美 =] 和 staging(类生产)环境。这将 运行 一个 alter table
语句来修改现有的 table.
注意:由于行是空的,所以不需要将nullable
或default value
设置为category_id
:
// 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: Enable SQLite foreign key constraints
Link 上面讨论了如何做到这一点,但本质上你需要在测试之前找到一种在你的功能测试环境中 运行 'PRAGMA foreign_keys=1' 的方法。
免责声明:我只在 Laravel 5
上试过这个
当 运行ning php artisan migrate
和 php artisan migrate:rollback
在 local[=35 上时,以下架构构建器代码 完美 =] 和 staging(类生产)环境。这将 运行 一个 alter table
语句来修改现有的 table.
注意:由于行是空的,所以不需要将nullable
或default value
设置为category_id
:
// 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: Enable SQLite foreign key constraints
Link 上面讨论了如何做到这一点,但本质上你需要在测试之前找到一种在你的功能测试环境中 运行 'PRAGMA foreign_keys=1' 的方法。
免责声明:我只在 Laravel 5
上试过这个