Book a Demo

Author Topic: Can't create foreign key  (Read 6465 times)

biske

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Can't create foreign key
« 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?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Can't create foreign key
« Reply #1 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
No, you can't have it!

biske

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Can't create foreign key
« Reply #2 on: August 23, 2009, 02:20:22 am »
I did what you said but have same problem. Maybe i wrong with direction of association?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Can't create foreign key
« Reply #3 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.
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Can't create foreign key
« Reply #4 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.
No, you can't have it!

biske

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Can't create foreign key
« Reply #5 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.
« Last Edit: August 23, 2009, 07:25:26 am by biske »

smendonc

  • EA User
  • **
  • Posts: 148
  • Karma: +5/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: Can't create foreign key
« Reply #6 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.

biske

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Can't create foreign key
« Reply #7 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.

Mike Fechner

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Can't create foreign key
« Reply #8 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).

biske

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Can't create foreign key
« Reply #9 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.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Can't create foreign key
« Reply #10 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
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!