diff --git a/app/models.py b/app/models.py index 280436fc..19567e00 100644 --- a/app/models.py +++ b/app/models.py @@ -987,7 +987,9 @@ class Client(Base, ModelMixin): # a referral can be attached to a client # so all users who sign up via the authorize screen are counted towards this referral - referral_id = sa.Column(sa.ForeignKey("referral.id"), nullable=True) + referral_id = sa.Column( + sa.ForeignKey("referral.id", ondelete="SET NULL"), nullable=True + ) icon = orm.relationship(File) user = orm.relationship(User) diff --git a/migrations/versions/2021_102612_bbedc353f90c_.py b/migrations/versions/2021_102612_bbedc353f90c_.py new file mode 100644 index 00000000..a9a31893 --- /dev/null +++ b/migrations/versions/2021_102612_bbedc353f90c_.py @@ -0,0 +1,31 @@ +"""empty message + +Revision ID: bbedc353f90c +Revises: d67eab226ecd +Create Date: 2021-10-26 12:05:38.840492 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'bbedc353f90c' +down_revision = 'd67eab226ecd' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint('client_referral_id_fkey', 'client', type_='foreignkey') + op.create_foreign_key(None, 'client', 'referral', ['referral_id'], ['id'], ondelete='SET NULL') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'client', type_='foreignkey') + op.create_foreign_key('client_referral_id_fkey', 'client', 'referral', ['referral_id'], ['id']) + # ### end Alembic commands ###