【发布时间】:2022-01-27 12:27:01
【问题描述】:
所以我正在尝试将表从 MySQL 迁移到 MSSQL (sql server migration assistant MySQL),但我收到此错误:
Migrating data...
Analyzing metadata...
Preparing table testreportingdebug.testcase...
Preparing data migration package...
Starting data migration Engine
Starting data migration...
The data migration engine is migrating table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 8855 rows total
Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Errors: Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Completing migration of table `testreportingdebug`.`testcase`...
Migration complete for table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 0 rows migrated (Elapsed Time = 00:00:00:01:352).
Data migration operation has finished.
0 table(s) successfully migrated.
0 table(s) partially migrated.
1 table(s) failed to migrate.
我刚刚从我的表中复制了三行,它们看起来是这样的:
'1', 'Pump# TimeToService', NULL, NULL, 'A general test case comment ...', '0'
'2', 'Config.SlaveMinimumReplyDelay', NULL, NULL, NULL, '0'
'3', 'Config.RESERVED', NULL, NULL, NULL, '0'
如果您想知道 MySQL 表中的冒号是如何设置的,请看这里:
是因为right, left and comment可以为空吗?
表的 DDL
CREATE TABLE `testcase` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`TestCaseName` varchar(150) DEFAULT NULL,
`Left` int(11) DEFAULT NULL,
`Right` int(11) DEFAULT NULL,
`Comment` text,
`Hidden` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Unique` (`Left`,`Right`)
) ENGINE=InnoDB AUTO_INCREMENT=10580 DEFAULT CHARSET=utf8
【问题讨论】:
-
MySQL 不会将 NULL 值视为 UNIQUE 约束中的重复项。 dev.mysql.com/doc/refman/8.0/en/… “唯一索引允许包含 NULL 的列有多个 NULL 值。” 而不是 SQL Server。 docs.microsoft.com/en-us/sql/relational-databases/tables/… “UNIQUE 约束允许值为 NULL。但是,与参与 UNIQUE 约束的任何值一样,每列只允许一个空值”。
-
@Akina 我只有在未设置为唯一的列中有 NULL 值,所以为什么会失败?
-
询问您的模型和迁移代码。
-
为表格发布 DDL,而不是图片的片段。
-
你有
UNIQUE KEY Unique (Left,Right),我看到这些左右列是NULL。
标签: mysql sql-server database-migration