0

Am using mysql and trying to drop foreign constraint, but i can't to delete that key.

SHOW CREATE TABLE xxxx;

its shows,

CREATE TABLE `xxxx` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `user_id` int(11) NOT NULL,
 `name` text NOT NULL,
 `article_title` text NOT NULL,
 `created_at` datetime NOT NULL,
 `last_modified_at` datetime NOT NULL,
 `latest_version` tinyint(4) NOT NULL,
 `status` tinyint(4) NOT NULL,
 `is_deleted` enum('0','1') NOT NULL,
 `deleted_time` datetime NOT NULL,
 `manual_authorgroup_data` text NOT NULL,
 PRIMARY KEY (`id`),
 KEY `user_id` (`user_id`),
 CONSTRAINT `fk_users_xxxx_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1

How to fix this issue, please help me.

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Mansoor H
  • 594
  • 1
  • 8
  • 25

1 Answers1

1

Try this,

ALTER TABLE `xxxx`
DROP FOREIGN KEY'fk_users_xxxx_user_id'
suguna
  • 781
  • 5
  • 14
  • select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where REFERENCED_TABLE_NAME = '’; You can use this syntax to know the foreign key name. Then try to drop.
    – suguna Oct 24 '16 at 13:15
  • REFERENCED_TABLE_NAME means?? – Mansoor H Oct 24 '16 at 13:18
  • The table referenced by foreign key. In your case, it is 'users'. – suguna Oct 24 '16 at 13:19