1

I have a database which have foreign key constraint I access database directly in MySQL WORKBENCH

Problem is , i need to delete single rows in the particular table. it shows foreign Key constraint error. Not able to delete rows. In PHPMYADMIN it have check box disable foreignkey checks.

Is like PHPMYADMIN , any option available in MySQL WORKBENCH I Searched and Didnt got anything. If you got idea kindly share.

Thank you

Kavin D
  • 474
  • 1
  • 4
  • 12
  • 1
    You are supposed to remove the value (or row(s)) in the table(s) that uses the referenced value before you delete the row in the referenced table. E.g.: delete all customers of country `xy` or replace the value `xy` in the customer-table with `null` or another country, *then* delete the row `xy` in the country-table. The foreign key is a measure to prevent you from invalidating your data (e.g. your joins might not work anymore). If your data model allows that: just remove the foreign key. If you still want to keep going despite all warnings: [try this](https://stackoverflow.com/a/15501754) – Solarflare Dec 02 '17 at 07:54
  • ok. any other solutions ? – Kavin D Dec 05 '17 at 11:53
  • What do you mean by other solutions? Somebody added the foreign key to prevent to delete a row in e.g. a country-table when that country is still used in e.g. an orders. You currently (in my example) try to delete such a country. So check if that is what you want to do. If you need help, explain what you are trying to do. Options: a) delete the "order" first. b) check if you do not need that relation (you want to generally allow orders to have countries that are not in the country table) and remove the foreign key c) if you are sure about what you want to do: use the code in the linked answer – Solarflare Dec 05 '17 at 12:44

0 Answers0