MySQL Workbench rename constraint -
i use mysql workbench design database , export sql create script. when run script create database, error - errno: 121.
it turns out mysql workbench gives 2 constraints same name, because both constraints use same key (i have table primary key 'roleid' , reference key in 2 other tables).
is there way how can rename constraint directly in designer, when forward engineer sql create script, give no errors?
i tried double click relation in designer , give new caption, still generates script original name.
part of generated script creates error:
create table if not exists users
.roles
( roleid
int not null auto_increment , ... primary key (roleid
) , ...); create table if not exists users
.userroles
( ... roleid
int not null , ... constraint roleid
foreign key (roleid
) references users
.roles
(roleid
));
create table if not exists users
.resourceprivileges
( roleid
int not null , ... constraint roleid
foreign key (roleid
) references users
.roles
(roleid
));
not sure how ended that. took mysql workbench spin, created 2 tables fk , created
-- ----------------------------------------------------- -- table `mydb`.`users` -- ----------------------------------------------------- create table if not exists `mydb`.`users` ( `idusers` int null , primary key (`idusers`) ) engine = innodb; -- ----------------------------------------------------- -- table `mydb`.`usersroles` -- ----------------------------------------------------- create table if not exists `mydb`.`usersroles` ( `users_idusers` int not null , primary key (`users_idusers`) , constraint `fk_usersroles_users` foreign key (`users_idusers` ) references `mydb`.`users` (`idusers` ) on delete no action on update no action) engine = innodb;
notice constraint has unique name 'fk_usersroles_users' not duplicated since uses table names. fun added relationship between same tables , default get
-- ----------------------------------------------------- -- table `mydb`.`usersroles` -- ----------------------------------------------------- create table if not exists `mydb`.`usersroles` ( `users_idusers` int not null , `users_idusers1` int not null , primary key (`users_idusers`, `users_idusers1`) , index `fk_usersroles_users1` (`users_idusers1` asc) , constraint `fk_usersroles_users` foreign key (`users_idusers` ) references `mydb`.`users` (`idusers` ) on delete no action on update no action, constraint `fk_usersroles_users1` foreign key (`users_idusers1` ) references `mydb`.`users` (`idusers` ) on delete no action on update no action) engine = innodb;
which again non problem (all of above auto generated - have set table names, primary key on referenced table , added 2 1:n relationships)
notes: version 5.2.30.
edit maybe happened preferences. default name fk constraints defined on model tab.
Comments
Post a Comment