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

Christopher Francisco

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?

kidshenlong

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

laravel migration:rollback gives error

From Dev

Laravel 5 migration error 1045

From Dev

Laravel 5 migration create table, got error class 'illuminate\database\schema' not found

From Dev

Laravel 5 migration: error while renaming columns

From Dev

route return view gives error Laravel 5

From Dev

Laravel migration with SQLite

From Dev

Test with PHPUnit Laravel 5 controller with database (Mock?)

From Dev

Test with PHPUnit Laravel 5 controller with database (Mock?)

From Dev

Laravel db migration - renameColumn error - Unknown database type enum requested

From Dev

Laravel Database Connection Error even after successful Migration

From Dev

Laravel session database duplicate key error index

From Dev

Database migration error

From Dev

Database migration error

From Dev

Laravel 5 Migration namespace

From Dev

Need to solve undefined index error in laravel 5

From Dev

Laravel Migration and seeding error

From Dev

Laravel 5.1 - Migration Error

From Dev

Laravel 5.1 - Migration Error

From Dev

Laravel 5.5 migration error

From Dev

SQLite Database gives warning automatic index on <table_name>(column) After upgrading Android L

From Dev

IllegalArgumentException the bind value index 1 is null with SQLite database in Android

From Dev

IllegalArgumentException the bind value index 1 is null with SQLite database in Android

From Dev

failed migration database with laravel 5.3

From Dev

Laravel 5.4 database migration not working

From Dev

Is it necessary to write down() for every up() in migration in laravel?

From Dev

Sqlite insert gives syntax error

From Dev

Django mptt database migration error

From Dev

Alter table Laravel 5 with migration

From Dev

android.database.sqlite.SQLiteException: near "ON": syntax error (code 1)

Related Related

  1. 1

    laravel migration:rollback gives error

  2. 2

    Laravel 5 migration error 1045

  3. 3

    Laravel 5 migration create table, got error class 'illuminate\database\schema' not found

  4. 4

    Laravel 5 migration: error while renaming columns

  5. 5

    route return view gives error Laravel 5

  6. 6

    Laravel migration with SQLite

  7. 7

    Test with PHPUnit Laravel 5 controller with database (Mock?)

  8. 8

    Test with PHPUnit Laravel 5 controller with database (Mock?)

  9. 9

    Laravel db migration - renameColumn error - Unknown database type enum requested

  10. 10

    Laravel Database Connection Error even after successful Migration

  11. 11

    Laravel session database duplicate key error index

  12. 12

    Database migration error

  13. 13

    Database migration error

  14. 14

    Laravel 5 Migration namespace

  15. 15

    Need to solve undefined index error in laravel 5

  16. 16

    Laravel Migration and seeding error

  17. 17

    Laravel 5.1 - Migration Error

  18. 18

    Laravel 5.1 - Migration Error

  19. 19

    Laravel 5.5 migration error

  20. 20

    SQLite Database gives warning automatic index on <table_name>(column) After upgrading Android L

  21. 21

    IllegalArgumentException the bind value index 1 is null with SQLite database in Android

  22. 22

    IllegalArgumentException the bind value index 1 is null with SQLite database in Android

  23. 23

    failed migration database with laravel 5.3

  24. 24

    Laravel 5.4 database migration not working

  25. 25

    Is it necessary to write down() for every up() in migration in laravel?

  26. 26

    Sqlite insert gives syntax error

  27. 27

    Django mptt database migration error

  28. 28

    Alter table Laravel 5 with migration

  29. 29

    android.database.sqlite.SQLiteException: near "ON": syntax error (code 1)

HotTag

Archive