Mysql cross-database foreign key -
I am trying to create a cross-database foreign key when I run the following code of the same database
CREATE TABLE `t1` (` id` integer (11) No NULL AUTO_INCREMENT, `int_id` varchar (128) utf8_unicode_ci NULL match, primary key (` ID`), unique key` int_id` ( `Int_id`)) engine = InnoDB default charge = utf8 COLLATE = utf8_unicode_ci; Table `t2` (` id` is not an integer (11) No NULL AUTO_INCREMENT, `ext_id` varchar (128) utf8_unicode_ci not match NULL, primary key (` id`), key `ext_id` (` ext_id`), constraint `t2_ibfk_1 Replace `` t1` (`int_id`) 'foreign key' (` ext_id`) engine CASCADE ON = engine = InnoDB default charset = UTF8 match = utf8_unicode_ci; However, when you make T1 on a database (D1) and then run the following code on a second database (D2), I get a normal error: # 1005 - Can not create the table 'userdata. T2 '(errno: 150) create table' T2` (`id 'int (11) tap etangement,` ext_id` varchar (128) utf8_unicode_ci null, primary Key Connection (`id`), key` ext_id` (`ext_id`), obstruct the foreign key (` ext_id`), reference 'd1.t1` (`int_id`) removed CASCADE ON) t2_ibfk_1` engine = InnoDB default Charge = UTF8 Calllet = UT F 8_inikod_si; Any help would be appreciated. Thanks!
Your syntax is not correct, try it
create table `T2` (` id` is not an integer (11) NULL AUTO_INCREMENT, `ext_id` varchar (128) utf8_unicode_ci NULL, Primary key match (` id`), key `ext_id` (` ext_id`), constraint `t2_ibfk_1` foreign Enter the key (`ext_id`) Referred` d1`. `T1` (` int_id`) CASCADE ON engine = InnoDB default charset = UTF8 match = utf8_unicode_ci;
Comments
Post a Comment