mariadb - Unable to delete automatically created index after deleting foreign key constraint - Stack Overflow

I am using the mariadb image mariadb:10.5.8 as my database.After deleting a foreign key constraint nam

I am using the mariadb image mariadb:10.5.8 as my database.

After deleting a foreign key constraint named fk_customers_store_user, when I ran show create table customers I got the following output:

| customers | CREATE TABLE `customers` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(36) DEFAULT NULL,
  `name` varchar(191) NOT NULL,
  `mobile` bigint(20) unsigned NOT NULL,
  `email` longtext NOT NULL,
  `image_url` longtext DEFAULT NULL,
  `owner_id` bigint(20) unsigned NOT NULL,
  `remarks` longtext DEFAULT NULL,
  `address` longtext DEFAULT NULL,
  `city` longtext DEFAULT NULL,
  `pincode` bigint(20) unsigned DEFAULT NULL,
  `state` longtext DEFAULT NULL,
  `cibil_score` bigint(20) unsigned DEFAULT NULL,
  `occupation` longtext DEFAULT NULL,
  `is_buyer` tinyint(1) DEFAULT 0,
  `is_seller` tinyint(1) DEFAULT 0,
  `is_referrer` tinyint(1) DEFAULT 0,
  `is_property_owner` tinyint(1) DEFAULT 0,
  `is_vehicle_owner` tinyint(1) DEFAULT 0,
  `created_at` datetime(3) DEFAULT NULL,
  `updated_at` datetime(3) DEFAULT NULL,
  `deleted_at` datetime(3) DEFAULT NULL,
  `is_deleted` tinyint(1) DEFAULT 0,
  `created_by` bigint(20) unsigned NOT NULL,
  `updated_by` bigint(20) unsigned NOT NULL,
  `alt_mobile` bigint(20) unsigned DEFAULT NULL,
  `location` longtext DEFAULT NULL,
  `source` longtext DEFAULT NULL,
  `store_id` bigint(20) unsigned NOT NULL,

  PRIMARY KEY (`id`),
  KEY `idx_customers_name` (`name`),
  KEY `fk_customers_store` (`store_id`),
  KEY `fk_customers_store_user` (`owner_id`),
  CONSTRAINT `fk_customers_owner` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_customers_store` FOREIGN KEY (`store_id`) REFERENCES `stores` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=27037 DEFAULT CHARSET=utf8mb4 |

As you can see in the output above there is a key with the same name as the foreign key constraint fk_customers_store_user. Now when I try to drop this key using the below queries:

alter table customers drop key fk_customers_store_user

or

alter table customers drop index fk_customers_store_user

I got the following error:

ERROR 1553 (HY000): Cannot drop index 'fk_customers_store_user': needed in a foreign key constraint

But I have already deleted the foreign key constraint in which it was needed. How can I drop this index ?

  1. I have already tried deleting the constraint and the index.
  2. Checking the deleted constraint name from schema after deleting the foreign key constraint using the query SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'customers';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744187695a4562285.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信