Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that relationship must be between a primary key and foreign key #1236

Closed
npatki opened this issue Feb 6, 2023 · 0 comments
Closed
Assignees
Labels
feature request Request for a new feature
Milestone

Comments

@npatki
Copy link
Contributor

npatki commented Feb 6, 2023

Version: SDV 1.0 (In development)

Problem Description

Currently, the metadata allows you add a relationship between two primary keys, as shown in #1232. This should not be allowed.

If you have a column that refers to another table, it must be a foreign key, not primary key.

Expected behavior

Running the code from #1232, we should throw an Error if you are specifying a relationship between 2 primary keys.

table = pd.DataFrame({
    'pk': list(range(100)),
    'col1': np.random.random(100),
    'col2': np.random.choice(['a', 'b', 'c'], 100)
})
data = {'table': table, 'table2': table}

metadata = MultiTableMetadata()
metadata.detect_table_from_dataframe('table', table)
metadata.set_primary_key('table', 'pk')

metadata.detect_table_from_dataframe('table2', table)
metadata.set_primary_key('table2', 'pk')

metadata.add_relationship('table', 'table2', 'pk', 'pk')

Output:

Invalid Metadata Error: A relationship must be specified between a primary key and non-primary key.

Additional context

The full specification is: A relationship must be between a primary key and a non-primary key.

We should also validate this this in the MultiTableMetadata.validate method.

@npatki npatki added the feature request Request for a new feature label Feb 6, 2023
@npatki npatki added this to the 1.0.0 milestone Feb 6, 2023
@npatki npatki changed the title Validate that relationship must be between a **primary key** and **foreign key** Validate that relationship must be between a primary key and foreign key Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

3 participants