Skip to content

Migration doesn't account for prefix when checking if migration table exists [bug] #3

Closed
@fideloper

Description

@fideloper

Original bug found here: https://github.com/illuminate/database/issues/111 - Moved to his repo as per Taylor. Here's the original text:

I spoke with Machuga in IRC - It was suggested I create an issue.

Issue:

Error after first migration: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'up_migrations' already exists

Steps to reproduce:

  1. Fresh install of L4
  2. Add a prefix to database in database connection config (MySql)
  3. Create a migration $ php artisan migrate:make create_users_table --table=users --create
  4. Fill in some fields, run the migration $ php artisan migrate
  5. Attempt a migrate:refresh $ php artisan migrate:refresh
  6. ERROR: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'up_migrations' already exists

Relevant files:

I tracked this down to this file: Illuminate\Database\MigrationsDatabaseMigrationRepository::repositoryExists() and specifically within that, the call to return $schema->hasTable($this->table); here

The $this->table variable passed to hasTable() does not include the table prefix. Illuminate\Database\Schema\MySqlBuilder::hasTable($table) does not check for prefix either.

Unfortunately I'm not yet familiar with the code/convention to know where you'd prefer to look up the prefix. (Not sure what class should have that "knowledge")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions