Reputation: 173
Okay, I understand what the problem is, I sort of understand constraints in that they need to be unique in the db (didn't really know that before now, so I learned something. Not sure what they are for at the moment, but can learn later. My problem is, I think a simple matter of not understanding how MySQL Workbench assigns constraints. Apparently, you can set it in options to do so automatically which I think I am setup to do; however, something that I did made many constraints the same because they used the same FK, here is an example of what I mean: Table 1:
CONSTRAINT `dish_type`
FOREIGN KEY (`dish_type` )
REFERENCES `acs_operations_dev`.`dish_types` (`id` )
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `tech_number`
FOREIGN KEY (`tech_number` )
REFERENCES `acs_operations_dev`.`employees` (`tech_number` )
ON DELETE NO ACTION
ON UPDATE CASCADE)
Table 2
PRIMARY KEY (`id`) ,
INDEX `tech_number` (`tech_number` ASC) ,
INDEX `car` (`car` ASC) ,
INDEX `field_dev_coach` (`field_dev_coach` ASC) ,
UNIQUE INDEX `etad_user_UNIQUE` (`etad_user` ASC) ,
CONSTRAINT `tech_number`
FOREIGN KEY (`tech_number` )
REFERENCES `acs_operations_dev`.`employees` (`tech_number` )
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `car`
FOREIGN KEY (`car` )
REFERENCES `acs_operations_dev`.`cars` (`id` )
ON DELETE NO ACTION
ON UPDATE CASCADE,
I left out some parts - just trying to show the problem - i.e. on tech_number.
I created the tables manually, on the model page (i.e. I did not use the EER "drawing" style). When I created the FKs, here is what I have done:
What is it that I am doing here that is causing WB to not auto-assign constraints? Also, what can I do to go back and fix it within WB.
I hope that makes sense. I used this method for every table, btw - so it is consistent across the board. Thanks!
Mike
Upvotes: 0
Views: 811
Reputation: 3523
Check that the tables are InnoDB
Check that the columns for the foreign key have the same data type. If you are using integer columns check that both are either unsigned or signed.
Check the names of the foreign keys they have to be unqiue. I usually use the following fromat fk_currenttablename_foreignkeytablename
Upvotes: 1