Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: biske on August 22, 2009, 09:27:03 pm

Title: Can't create foreign key
Post by: biske on August 22, 2009, 09:27:03 pm
I have for example two tables books(book_id(PK), name) and rental_books(rental_id (PK), book_id, date).
It's on the data diagram of course. I linked tables books and rental_books where books is parent and rental_books is child. Then i press right click on relationship and then "Foreign Keys..". In the form Foreign Key Constraint  i choose book_id from books and book_id form rental_books and i get error "Destination column(s) is not part of the primary key or is not unique". But i don't want that book_id is part of the primary key in table rental_books. Also it has to be that i can rent book more times, not just once so it can't be unique..How to solve it?
Title: Re: Can't create foreign key
Post by: «Midnight» on August 23, 2009, 01:28:41 am
Verify that the two tables have a DBMS assigned (and the same one of course). Use the Properties dialog.

You should also check the Settings | Database Datatypes dialog to confirm that there is a default database. The way the dialog works is a bit strange (but Sparx has not improved it despite feature requests). You need to set a DBMS in the drop-down list, then look to see if the check box for default becomes checked. [Of course you can check the box yourself after selecting a DBMS, which changes the default to your selection.]

HTH, David
Title: Re: Can't create foreign key
Post by: biske on August 23, 2009, 02:20:22 am
I did what you said but have same problem. Maybe i wrong with direction of association?
Title: Re: Can't create foreign key
Post by: «Midnight» on August 23, 2009, 05:34:39 am
Perhaps.

Check that the diagram you created is a Data Model diagram, not simply a class (logical) diagram. EA is sensitive to the diagram type.
Title: Re: Can't create foreign key
Post by: «Midnight» on August 23, 2009, 05:36:43 am
I see in another of your posts that you are still using Build 815. I think the above suggestions also apply though.
Title: Re: Can't create foreign key
Post by: biske on August 23, 2009, 07:23:01 am
I have dialup internet, so can not download it. I will try to download in some other way.
I attached my model on rapidshare so you can look and see what is problem. Here is adress:
http://rapidshare.com/files/270324979/Biblioteka_v2.6.3.rar.html
Try to link and make foreign key between tables BIBLIOTEKAR and IZNAJMLJIVANJE_KNJIGE.
Title: Re: Can't create foreign key
Post by: smendonc on August 23, 2009, 05:38:04 pm
The data modeling profile is very particular.  I created the primary/foreign key link without the error message.  I did get the error when I didn't specify the cardinality and directionality of the association.  Here's the exact procedure I used. You will need to try it and let us know if this is the result you are trying to achieve.

1. Dropped the BIBLIOTEKAR and IZNAJMLJIVANJE_KNJIGE onto an empty data model diagram.
2. Added the column sifa_bibliotekara as LONG to IZNAJMLJIVANJE_KNJIGE
2. Created a directed association starting from IZNAJMLJIVANJE_KNJIGE to BIBLIOTEKAR
3. Set the cardinality at the IZNAJMLJIVANJE_KNJIGE end to 0..*
4. Set the cardinality at the BIBLIOTEKAR end to 1
5. Right clicked on the assoication and chose foreign keys.
6. I choose the sifa_bibliotekara column for both tables
7. The foreign key constraint was created on table IZNAJMLJIVANJE_KNJIGE

Stan.
Title: Re: Can't create foreign key
Post by: biske on August 23, 2009, 07:41:26 pm
ok, it works. but i thought that i have to create directed association starting from BIBLIOTEKAR to IZNAJMLJIVANJE_KNJIGE because BIBLIOTEKAR is parent, IZNAJMLJIVANJE_KNJIGE is child.
Title: Re: Can't create foreign key
Post by: Mike Fechner on August 23, 2009, 08:55:51 pm
In UML usually the child points to the parent as teh parent can stand for it's own, and the child is dependent from the parent.

That's different from most ERD diagramming utilities (like ErWin).
Title: Re: Can't create foreign key
Post by: biske on August 23, 2009, 11:47:08 pm
You are right, it's my first project for database in UML, and last project i worked in ERwin..Thanks again.
Title: Re: Can't create foreign key
Post by: Paolo F Cantoni on August 24, 2009, 11:45:28 am
Quote
In UML usually the child points to the parent as the parent can stand for it's own, and the child is dependent from the parent.

That's different from most ERD diagramming utilities (like ERWin).
And also because, in the main, in UML the destination is the "Supplier" and the origin the "Client".

Embarcadero ER/Studio also requires that you select the "parent" first and the "child" second.

Paolo