Foreign keys

Use the Cúram generator to create foreign keys between database tables.

A foreign key relationship between two database tables is specified in the input model by adding a relationship of stereotype foreignkey (one word, no spaces) between two entity classes. Optionally you can give the relationship a name, this name is then applied to the foreign key constraint added to the database. Otherwise the database chooses its own name for the constraint.

The following rules apply when using foreign keys:

  • Foreign key relationships are allowed on entity classes only.
  • Fields referenced by a foreign key will be set to unique, as this is required by some databases.
  • If the foreign key references the primary key of another entity, a redundant unique clause will not be generated by the generator, as the primary key is already unique.
  • Foreign keys cannot be specified on subclass entities. The relationship should be specified using the actual base entity classes themselves.