sdv.metadata.dataset.Metadata.add_relationship

Metadata.add_relationship(parent, child, foreign_key=None, validate=True)[source]

Add a new relationship between the parent and child tables.

The relationship is created by adding a reference (ref) on the foreign_key field of the child table pointing at the parent primary key.

Parameters
  • parent (str) – Name of the parent table.

  • child (str) – Name of the child table.

  • foreign_key (str) – Field in the child table through which the relationship is created. If None, use the parent primary key name.

  • validate (bool) – Whether to validate metadata after adding this relationship or not. Defaults to True.

Raises

ValueError – If any of the following happens: * The parent table does not exist. * The child table does not exist. * The parent table does not have a primary key. * The foreign_key field already exists in the child table. * The child table already has a parent. * The new relationship closes a relationship circle.