OHDSI / OHDSI/CommonDataModel

Table PERSON vs EPISODE) foreign key columns to match exactly

Open Beginner friendly
#784 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
1.1k
Forks
508
Avg merge
1h 30m
Merged PRs (30d)
3

Description

SQL Server requires foreign key columns to match exactly.
integer ≠ bigint, so SQL Server refuses to create the FK

How to Fix It
You have two options — choose the one that matches your data model.

Option 1 — Make PERSON.person_id a BIGINT
This is the most common fix if your IDs can grow large.

Option 2,. Not fit for us, as int is not appropriate for person key.

Important Note (OMOP CDM)
Since you’re clearly building OMOP CDM:

PERSON.person_id must be BIGINT

EPISODE.person_id must also be BIGINT

So you’re absolutely doing the right thing.

===============================================
ALTER TABLE PERSON
ALTER COLUMN person_id BIGINT NOT NULL;

ALTER TABLE EPISODE
ADD CONSTRAINT fpk_EPISODE_person_id
FOREIGN KEY (person_id) REFERENCES PERSON(person_id);

ALTER TABLE PERSON
DROP CONSTRAINT xpk_PERSON;

ALTER TABLE PERSON
ALTER COLUMN person_id BIGINT NOT NULL;

ALTER TABLE PERSON
ADD CONSTRAINT xpk_PERSON PRIMARY KEY (person_id);

ALTER TABLE EPISODE
DROP CONSTRAINT fpk_EPISODE_person_id;

ALTER TABLE EPISODE
ADD CONSTRAINT fpk_EPISODE_person_id
FOREIGN KEY (person_id) REFERENCES PERSON(person_id);

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the PERSON and EPISODE table definitions and their key constraints in the repository's DDL. Compare the person_id types, then verify that both use BIGINT and that the foreign key can be created successfully on SQL Server.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.