Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Workbench - adding relations without having to edit the tables

I am editing a schema in MySQL workbench. I imported the schema from a mysqldump. Since it doesn't include any foreign keys, I am adding the relationships manually.

Here is my problem: When adding a relationship, workbench adds a column with the foreign key to one of the tables. However, the column is already present. I have to remove the current column and change the name of the new column to the name of the original column.

I illustrated it in the attached pictures:

  1. The two original tables
  2. The two tables after adding the relationship
  3. After removing original column and renaming new column - this is what I want in one step

The two original tablesThe two tables after adding the relationshipAfter removing original column and renaming new column - this is what I want in one step

Is there a way to avoid this, and choose the target-column when adding the relationship, so that I don't have to edit a larger number of tables?

(Edited to add: The example tables are not the tables I want to connect, in case somebody recognizes the Drupal 8 tables - they were just short enough to aid as an example).

like image 973
Ursula Avatar asked Oct 19 '13 19:10

Ursula


Video Answer


1 Answers

Most of the relationship commands automatically create columns to host the new relationship. However, there's one tool that allows to select existing columns for a 1:n relationship. See in the tools toolbar. The last icon contains a picker symbol. This is the one to use. For quick access simply press '6'.

like image 90
Mike Lischke Avatar answered Oct 18 '22 15:10

Mike Lischke