[MDEV-17599] ALTER TABLE DROP CONSTRAINT does not work for foreign keys Created: 2018-11-02  Updated: 2020-08-25  Resolved: 2019-02-05

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 10.2.18, 10.3.7
Fix Version/s: 10.2.22, 10.3.13

Type: Bug Priority: Critical
Reporter: Valerii Kravchuk Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-17579 DROP CONSTRAINT implementation is inc... Closed

 Description   

The syntax is supported in MariaDB 10.2.1 (https://mariadb.com/kb/en/library/alter-table/#drop-constraint), but it doesn't work for foreign key constraints:

MariaDB [test]> create table tpk(id int primary key, c1 int);
Query OK, 0 rows affected (0.646 sec)
 
MariaDB [test]> create table tfk(id int primary key, c1 int, constraint `_________fk_transaction_111_11111_1111_111_id` FOREIGN KEY (`c1`) REFERENCES tpk (`id`)
 ON DELETE NO ACTION ON UPDATE NO ACTION);
Query OK, 0 rows affected (0.416 sec)
 
MariaDB [test]> show create table tfk\G
*************************** 1. row ***************************
       Table: tfk
Create Table: CREATE TABLE `tfk` (
  `id` int(11) NOT NULL,
  `c1` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `_________fk_transaction_111_11111_1111_111_id` (`c1`),
  CONSTRAINT `_________fk_transaction_111_11111_1111_111_id` FOREIGN KEY (`c1`)
REFERENCES `tpk` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.007 sec)
 
MariaDB [test]> alter table tfk drop constraint `_________fk_transaction_111_111
11_1111_111_id`;
ERROR 1091 (42000): Can't DROP CONSTRAINT `_________fk_transaction_111_11111_111
1_111_id`; check that it exists
MariaDB [test]> alter table tfk drop foreign key `_________fk_transaction_111_11
111_1111_111_id`;
Query OK, 0 rows affected (0.129 sec)
Records: 0  Duplicates: 0  Warnings: 0

See also MDEV-14873.



 Comments   
Comment by Elena Stepanova [ 2018-11-02 ]

Assigning to serg for re-distribution.

Comment by Alexey Botchkov [ 2019-01-31 ]

http://lists.askmonty.org/pipermail/commits/2019-January/013348.html

Comment by Alexey Botchkov [ 2019-02-04 ]

http://lists.askmonty.org/pipermail/commits/2019-February/013367.html

Comment by Alexey Botchkov [ 2019-02-05 ]

http://lists.askmonty.org/pipermail/commits/2019-February/013373.html

Generated at Thu Feb 08 08:37:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.