Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming sqlite table with unique index throws "index already exists" #1343

Open
karrakoliko opened this issue Jul 25, 2023 · 1 comment
Open

Comments

@karrakoliko
Copy link

karrakoliko commented Jul 25, 2023

Bug Report

Q A
BC Break no
Version 3.6.0.0

Summary

When i try rename sqlite table that contains index, i get exception "index *** already exists".

Current behavior

An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1 index *your_index_name* already exists

How to reproduce

  1. Create sqlite table
  2. Create unique index on any column of this table
  3. Create migration that renames table:
 $schema->renameTable('oldTableName', 'newTableName');

Demo repo: https://github.com/karrakoliko/doctrine-migrations-sqlite-driver-is-broken-example

Expected behavior

Table renamed (recreated with all the indexes, keys, etc., in case of sqlite)

Workaround tried (no success)

I tried workaround, but no success:
Drop index in preUp hook, then recreate it in postUp hook. I ensured both hooks executed. Index successfully dropped, but not created (silently: no error appeared). $table->hasIndex(indexName) returns true, but index never created.

@karrakoliko
Copy link
Author

karrakoliko commented Jul 26, 2023

Workaround that works: to rename table use 3 migrations instead of one:

  1. migration that drops indexes
  2. migration that renames table
  3. migration that restores (re-creates) indexes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant