SymmetricDS与三键外键混淆

时间:2015-04-11 19:06:54

标签: mysql jdbc symmetricds

我有一个应该使用SymmetricDS同步的数据库。有以下查询,构建基础:

CREATE TABLE `defectstdreference` (
  `std_doc_id` bigint(20) NOT NULL COMMENT 'Идентификатор НТД',
  `improve_notice_doc_id` bigint(20) NOT NULL COMMENT 'Идентификатор предписания',
  `defect_id` int(11) NOT NULL COMMENT 'Идентификатор дефекта',
  `paragraph` varchar(4000) NOT NULL COMMENT 'Пункт НТД',
  `reference_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Идентификатор ссылки на пункт НТД',
  `client_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`reference_id`),
  KEY `Relationship70` (`std_doc_id`),
  KEY `Relationship72` (`improve_notice_doc_id`,`defect_id`,`client_id`),
  CONSTRAINT `Relationship70` FOREIGN KEY (`std_doc_id`) REFERENCES `std` (`doc_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `Relationship72` FOREIGN KEY (`improve_notice_doc_id`, `defect_id`, `client_id`) REFERENCES `improvementnoticedefect` (`doc_id`, `defect_id`, `client_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COMMENT='Ссылки на НТД выявленных нарушений';

和引用的表:

CREATE TABLE `improvementnoticedefect` (
  `description` varchar(20000) NOT NULL COMMENT 'Описание нарушения',
  `defect_id` int(11) NOT NULL COMMENT 'Номер нарушения в рамках предписания',
  `doc_id` bigint(20) NOT NULL COMMENT 'Номер документа "Предписание"',
  `client_id` bigint(20) NOT NULL,
  PRIMARY KEY (`doc_id`,`defect_id`,`client_id`),
  KEY `Relationship68` (`doc_id`,`client_id`),
  CONSTRAINT `Relationship68` FOREIGN KEY (`doc_id`, `client_id`) REFERENCES `improvementnotice` (`doc_id`, `client_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Дефект';

如您所见,表impovementnoticedefect的主键和defectstdreference的fk约束72中的列顺序相同。

然而,当同步开始时,SymmetricDS给出了错误:

Cannot add foreign key constraint.  Failed to execute: ALTER TABLE `defectstdreference`
    ADD CONSTRAINT `Relationship72` FOREIGN KEY (`improve_notice_doc_id`, `defect_id`, `client_id`) REFERENCES `improvementnoticedefect` (`doc_id`, `defect_id`, `client_id`)

当我尝试为SymmetricDS创建的表转储sql时,我得到以下内容:

CREATE TABLE `improvementnoticedefect` (
  `defect_id` int(11) NOT NULL,
  `doc_id` bigint(20) NOT NULL,
  `client_id` bigint(20) NOT NULL,
  `description` varchar(20000) NOT NULL,
  PRIMARY KEY (`defect_id`,`doc_id`,`client_id`),
  KEY `Relationship68` (`doc_id`,`client_id`),
  CONSTRAINT `Relationship68` FOREIGN KEY (`doc_id`, `client_id`) REFERENCES `improvementnotice` (`doc_id`, `client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

如您所见,主键中字段的顺序不同。

我尝试手动运行错误的查询,但它出错了,但是当我更改了字段的顺序时,一切都很好。

我该如何解决这个问题?有什么配置我应该做或smth?我真的很绝望,有人可以帮忙吗?

更新 我已经意识到,问题是SymmetricDS使用XML发送表,而PK是从XML创建的:

<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
<database name="dataextractor">
    <table name="improvementnoticedefect">
         <column name="defect_id" primaryKey="true" required="true" type="INTEGER" size="10">
             <platform-column name="mysql" type="INT" size="10"/>
         </column>
         <column name="doc_id" primaryKey="true" required="true" type="BIGINT" size="19">
             <platform-column name="mysql" type="BIGINT" size="19"/>
         </column>
         <column name="client_id" primaryKey="true" required="true" type="BIGINT" size="19">
             <platform-column name="mysql" type="BIGINT" size="19"/>
         </column>
         <column name="description" required="true" type="VARCHAR" size="20000">
             <platform-column name="mysql" type="VARCHAR" size="20000"/>
         </column>
         <foreign-key name="Relationship68" foreignTable="improvementnotice">
             <reference local="doc_id" foreign="doc_id"/>
             <reference local="client_id" foreign="client_id"/>
         </foreign-key>
     </table>
</database>

你可以看到,这个XML主键是按创建列的顺序生成的,实际上是错误的

0 个答案:

没有答案