newbies seeking help on creating a ER diagram (reverse engineering)

Hi,

First i appologized if my questions are too basic, but i’ve tried out for quite long without getting the answer…

I’ve tried to create an ER diagram through both ways
(1) reverse engineering from DDL script
(2) manually

For both ways, i faced one same question.

When i create a relationship, the PK in my parent_table appeared as PFK in my child_table as a new attribute.
I already created the key in my child_table so i do not want it.

My parent_tableCREATE TABLE DefaultDatabase.parent_tb
(
PARENT_ID Bigint UNSIGNED NOT NULL AUTO_INCREMENT,
INSERT_DATE Datetime NOT NULL,
UPDATE_DATE Datetime,
PRIMARY KEY (PARENT_ID)
) ENGINE = InnoDB;

My child_tableCREATE TABLE DefaultDatabase.child_tb
(
PARENT_ID Bigint UNSIGNED NOT NULL,
CHILD_ID Varchar(20) NOT NULL,
POST_TYPE_ID Tinyint UNSIGNED NOT NULL,
INSERT_DATE Datetime NOT NULL
) ENGINE = InnoDB;
ALTER TABLE DefaultDatabase.child_tb ADD PRIMARY KEY (PARENT_ID,CHILD_ID,POST_TYPE_ID)

When i create ER diagram through the reverse engineering, it appears like this.

**parent_tb
**---------------
parent_id(PK)

insert_date
update_date

child_tb---------------
parent_id(PK)
child_id(PK)
post_type_id(PK)

It is no problem at this stage.

BUT when i join the relationship, it appears like this in the child_tb

parent_id(PK)
child_id(PK)
post_type_id(PK)
parent_id(PFK) <----this was added--------------

Maybe my way to craete the ER diagram is wrong…
How to make the original parent_id(PK) to parent_id(PFK) without adding another individual elements to it?

Thank you.

i guess i need to learn more about DB
i should have wrote the FK definition in my DDL.

anyway, solved.

thanks.

Hi,

just add new PK to parent entity and draw identifying or non-identifying relationship to chiild table. The attribute will migrate to child entity as PFK or FK. No need to create PK in child table in advance.

BTW: version 4.2 include Automatic Foreign Keys Mapping feature that will allow you to map existing attribute in child table with key attribute in parent table.

Regards,

Vaclav

thanks!
i’m importing the DDL, so the PK is created in the schema.
I did not create FK for it, so that’s the reason…
thanks anyway!

Hi,

OK, try to use the latest version then. It includes Automatic Foreign Keys Mapping feature.

Regards,

Vaclav