"""Deleting a quiz must not destroy the questions extracted for it. `questions.quiz_id` was created ON DELETE CASCADE, while the model has long declared SET NULL and its comment says the column is informational — "which quiz this question was originally extracted for" — with real membership held in `quiz_question_links`. The database was the one being obeyed, so removing a quiz silently erased every question it had produced, along with their attempts, exam membership, media and article links, and straight past the trash that was built to make exactly that impossible. The model's intent is the correct one and is what this applies. `quizzes.user_id` is the opposite case: the database cascades and the model said nothing, and here the database is right — deleting an account is documented as removing what it made. The model is corrected to match rather than the data. Revision ID: b8c9d0e1f2a3 Revises: a7b8c9d0e1f2 """ from alembic import op revision = "b8c9d0e1f2a3" down_revision = "a7b8c9d0e1f2" branch_labels = None depends_on = None def upgrade() -> None: op.drop_constraint("questions_quiz_id_fkey", "questions", type_="foreignkey") op.create_foreign_key("questions_quiz_id_fkey", "questions", "quizzes", ["quiz_id"], ["id"], ondelete="SET NULL") def downgrade() -> None: op.drop_constraint("questions_quiz_id_fkey", "questions", type_="foreignkey") op.create_foreign_key("questions_quiz_id_fkey", "questions", "quizzes", ["quiz_id"], ["id"], ondelete="CASCADE")