Skip to content

Conversation

@yuvmen
Copy link
Member

@yuvmen yuvmen commented Nov 19, 2025

While these FKs are supposed to have CASCADE on them according to our models, they are in fact not in the DB. Trying to run this to force them to be CASCADE in production

While these FKs are supposed to have CASCADE on them according to our models, they are in
fact not in the DB. Trying to run this to force them to be CASCADE
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/monitors/migrations/0013_fix_monitorincident_checkin_cascade.py

for 0013_fix_monitorincident_checkin_cascade in monitors

--
-- Alter field starting_checkin on monitorincident
--
-- (no-op)
--
-- Alter field resolving_checkin on monitorincident
--
-- (no-op)

Comment on lines +30 to +39
migrations.AlterField(
model_name="monitorincident",
name="starting_checkin",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="created_incidents",
to="monitors.monitorcheckin",
),
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't generating any SQL in CI, and it might not generate any SQL in production either as django's state before this migration is run indicates that the on_delete action is already present. If you use a SeparateDatabaseAndState operation instead you could rebuild the constraint via SQL to ensure that the constraint is created to match django's state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that we actually do this across the board, that our FKs have Cascades at the django level but not in the DB generally. I think I will solve this in the more canonical way of deleting the child relations manually using a deletion task instead of letting the DB do it, which seems like we dont usually do.

@yuvmen
Copy link
Member Author

yuvmen commented Nov 20, 2025

Will solve this through manual deletion of child relations, not by changing the way we work with DB foreign keys.

@yuvmen yuvmen closed this Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants