I have a table 'release_group' and another table 'release' , for example:
release_group ------------------------ release_group_id (PRIMARY KEY) name main_release_id (FOREIGN KEY) release ------------------------ release_id (PRIMARY KEY) release_group_id (FOREIGN KEY) name
If I create a release line, release_group_id is not available, simply because it has not been created yet. But I cannot create a release_group string without main_release_id . So this is not a random situation.
EDIT: The main_release_id in the release_group should say that the release is the main of the group, the one that I will use the link.
What is the professional way to handle this case?
1. Remove the foreign key index main_release_id in the release_group table and specify the ALLOW NULL attribute. Create a release_group string so that I can apply its id to the release string.
2. Save the foreign key index 'main_release_id' in the table 'release_group' and assign it a temporary integer value of 0. Create a release line and update the foreign key in release_group accordingly? Keep in mind that if this is the way, I can accidentally get foreign keys with a value of 0, which I don’t know if this ethics is in the database?
What is the professional way to handle this case?
thanks
source share