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

[NFR] Drop foreign keys before column drop #6

Open
Jurigag opened this issue Sep 28, 2016 · 1 comment
Open

[NFR] Drop foreign keys before column drop #6

Jurigag opened this issue Sep 28, 2016 · 1 comment
Assignees
Labels
NFR New Feature Request

Comments

@Jurigag
Copy link

Jurigag commented Sep 28, 2016

Let's assume that we have in current database some foreign key on location.instrument_id. Lets assume that we are deleting this column. This won't work because there is existing foriegn key.

ERROR: SQLSTATE[HY000]: General error: 1828 Cannot drop c
olumn 'instrument_id': needed in a foreign key constraint 'suzuki_test/location_ibfk_2'

Phalcon migration should check if there is any foreign key like:

select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME
from information_schema.KEY_COLUMN_USAGE
where TABLE_NAME = :currentTable: AND COLUMN_NAME = :currentColumn: AND REFERENCED_COLUMN_NAME IS NOT NULL;

Then on result from it it should delete all constraint with CONSTRAINT_NAME.

@Jurigag Jurigag changed the title [NFR]Drop indexes before column drop [NFR]Drop foreign keys before column drop Sep 28, 2016
@sergeysviridenko
Copy link

sergeysviridenko commented Sep 27, 2017

@Jurigag I'm not sure that deleting is good way. FK is may cause problems when during on generating or running migration. But we can implement workflow with FK to store keys in the file. For example: user runs command generate --FK and DevTools will create file called foreignKeys.sql with real SQL. After that we can delete it from DB. I guess this way is better. How do you think about this?

@sergeyklay sergeyklay transferred this issue from phalcon/phalcon-devtools Oct 21, 2019
@Jeckerson Jeckerson added the NFR New Feature Request label Nov 12, 2019
@Jeckerson Jeckerson added this to the 1.1.x milestone Nov 24, 2019
@Jeckerson Jeckerson self-assigned this Jan 28, 2020
@Jeckerson Jeckerson modified the milestones: 1.1.x, 1.2.x Jan 28, 2020
@Jeckerson Jeckerson modified the milestones: 1.2.x, 2.0.x Feb 23, 2020
@Jeckerson Jeckerson changed the title [NFR]Drop foreign keys before column drop [NFR] Drop foreign keys before column drop Mar 19, 2020
@Jeckerson Jeckerson modified the milestones: 2.0.x, 2.1.x, 3.0.x Mar 19, 2020
@niden niden moved this to Backlog in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
@Jeckerson Jeckerson removed this from the 3.0.x milestone May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NFR New Feature Request
Projects
Status: Backlog
Development

No branches or pull requests

3 participants