6

The following schema builder code works perfectly when running php artisan migrate and php artisan migrate:rollback on local and staging (production-like) environment. This will run an alter table statement to modify an existing table.

Note: since rows are empty, there is no need to set nullable or default value to the 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');

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)

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?

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

1 Answers1

2

By default SQLite has foreign key support disabled.

You'll need to enabled it manually or use a different DB.

Laravel 5.1: Enable SQLite foreign key constraints

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.

Disclaimer: I've only tried this on Laravel 5

Community
  • 1
  • 1
kidshenlong
  • 552
  • 6
  • 16