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

DBAL-837: Cannot drop index needed in a foreign key constraint #2072

Closed
doctrinebot opened this issue Mar 17, 2014 · 11 comments
Closed

DBAL-837: Cannot drop index needed in a foreign key constraint #2072

doctrinebot opened this issue Mar 17, 2014 · 11 comments
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user cmodijk:

I'm trying to remove an relation from an entity and i'm getting an error that it could not be executed. After testing it, it's missing the DROP FOREIGN KEY query.

The generated SQL is:
{quote}
DROP INDEX IDX_DCE815B325C79A8C ON moveMembers;
ALTER TABLE moveMembers DROP fkAccessId;
{quote}

When I use --force to execute it I get the following error:
{quote}
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'DROP INDEX IDX_DCE815B325C79A8C ON moveMembers':

SQLSTATE[HY000]: General error: 1553 Cannot drop index 'IDX_DCE815B325C79A8C': needed in a foreign key constraint

[PDOException]
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'IDX_DCE815B325C79A8C': needed in a foreign key constraint
{quote}

@doctrinebot
Copy link
Author

@doctrinebot
Copy link
Author

Comment created by cmodijk:

Maybe related to DBAL-732?

@tomasfejfar
Copy link

Actual link for the related issue is #1958

@tomasfejfar
Copy link

tomasfejfar commented Jan 27, 2017

Workaround for this would be to manually save the migration SQL and prefix it with foreign key drop. Then append FK's create query as well. Then run the whole thing. Unfortunately it's very error-prone. Nevertheless, it's the best workaround we've been able to come up with at the moment.

You can copy the FK's specification from SHOW CREATE TABLE table_name query.

@podorozhny
Copy link

ping

@Ocramius
Copy link
Member

@podorozhny pinging is useless - open a PR with a failing test case.

@phpepe
Copy link

phpepe commented Apr 3, 2018

I've the same problem here.
Solved by sending a manual query before the migration:
ALTER TABLE [tablename] DROP FOREIGN KEY IDX_xxx ;
instead of generated SQL:
DROP INDEX IDX_xxx ON [tablename];

@morozov
Copy link
Member

morozov commented Apr 3, 2018

@phpepe is it related to #2929?

@phpepe
Copy link

phpepe commented Apr 3, 2018

hmm I don't think so, its not related with Primary key, its just foreign key column removal

@SCIF
Copy link

SCIF commented Apr 3, 2018

Hi @phpepe , may be this one?

@github-actions
Copy link

github-actions bot commented Oct 4, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants