Skip to content

Laravel 11 SQLite Migration Failure: after drop column: unknown column "XXXXXX" in foreign key definition #51318

Closed
@Gandhi11

Description

@Gandhi11

Laravel Version

11.6.0

PHP Version

8.3.6

Database Driver & Version

SQLite 3.45.1

Description

In Laravel 11, running tests in memory using SQLite I receive this error when trying to drop a column that have a foreign key on it. That wasn't a problem before when using doctrine/dbal (#48864).

Steps To Reproduce

  1. Create a new Laravel project.
  2. Add a new migration that drop the user_id column on the sessions table like so:
Schema::table('sessions', function (Blueprint $table) {
    $table->dropColumn('user_id');
});
  1. Setup PHPUnit for testing with the connection set to SQLite and the database set to :memory:.
  2. Add use RefreshDatabase; in the default TestCase class
  3. Run the test test_the_application_returns_a_successful_response.
  4. You should receive the following error:
There was 1 error:

1) Tests\Feature\ExampleTest::test_the_application_returns_a_successful_response
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 error in index sessions_user_id_index after drop column: no such column: user_id (Connection: sqlite, SQL: alter table "sessions" drop column "user_id")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions