简体   繁体   中英

how to delete foreign key in mysql

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.

Try this,

ALTER TABLE `xxxx`
DROP FOREIGN KEY'fk_users_xxxx_user_id'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM