Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue of add foreign key failed but doesn't rollback #39582

Closed
crazycs520 opened this issue Dec 2, 2022 · 0 comments · Fixed by #39583
Closed

issue of add foreign key failed but doesn't rollback #39582

crazycs520 opened this issue Dec 2, 2022 · 0 comments · Fixed by #39583

Comments

@crazycs520
Copy link
Contributor

Reproduce

 set @@global.tidb_enable_foreign_key=1;
set @@foreign_key_checks=1;
create table t1 (id int key,a int, index(a));
create table t2 (id int key,a int);
insert into t1 values (1,1);
test> ALTER TABLE t1 ADD foreign key fk(a) references t2(id) ON DELETE CASCADE;
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `fk` FOREIGN KEY (`a`) REFERENCES `t2` (`id`) ON DELETE CASCADE)')
test> show create table t1\G
***************************[ 1. row ]***************************
Table        | t1
Create Table | CREATE TABLE `t1` (
  `id` int(11) NOT NULL,
  `a` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
  KEY `a` (`a`),
  CONSTRAINT `fk` FOREIGN KEY (`a`) REFERENCES `test`.`t2` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

Add foreign key failed, but show create table result still contain the foreign key info.

TiDB Version

***************************[ 1. row ]***************************
tidb_version() | Release Version: v6.5.0-alpha-248-g6b4739f170
Edition: Community
Git Commit Hash: 6b4739f170a1fb53a10d3f4bd50ad6288460f252
Git Branch: master
UTC Build Time: 2022-12-02 06:31:34
GoVersion: go1.19.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant