Mysql script error for multiply primary key defined
Cricle opened this issue · 2 comments
Cricle commented
In mysql8.0.x
Table has 3 PK.
Generated sql is
CREATE TABLE `sakila1`.`actor`
(
`actor_id` BIGINT(40) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`first_name` VARCHAR(45) NOT NULL,
`last_name` VARCHAR(45) NOT NULL,
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE `sakila1`.`actor` ADD CONSTRAINT `PRIMARY` PRIMARY KEY (`actor_id`, `first_name`, `last_name`); --error
CREATE INDEX `idx1` ON `sakila1`.`actor`(`first_name`);
martinjw commented
In my local mysql db I used the standard sakila.actor table (pk with 1 column) and a copy (actor2) with a pk of 3 columns.
var generatorFactory = new DdlGeneratorFactory(SqlType.MySql);
var generator = generatorFactory.TableGenerator(schema.FindTableByName("actor"));
var txt = generator.Write();
var generator2 = generatorFactory.TableGenerator(schema.FindTableByName("actor2"));
txt += generator2.Write();
Console.WriteLine(txt);
The output is correct- primary keys are built correctly. What is the original create table for your table (perhaps generated with workench?)
CREATE TABLE `sakila`.`actor`
(
`actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`first_name` VARCHAR(45) NOT NULL,
`last_name` VARCHAR(45) NOT NULL,
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX `idx_actor_last_name` ON `sakila`.`actor`(`last_name`);
CREATE TABLE `sakila`.`actor2`
(
`actor_id` BIGINT UNSIGNED NOT NULL,
`first_name` VARCHAR(45) NOT NULL,
`last_name` VARCHAR(45) NOT NULL,
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE `sakila`.`actor2` ADD CONSTRAINT `PRIMARY` PRIMARY KEY (`actor_id`, `first_name`, `last_name`);
Cricle commented
Very thanks the project and author.
Now I closed the issuer.