From faa82e7b5a9962f95cbe5866847eed2f971507f4 Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 5 Mar 2020 17:00:43 +0100 Subject: [PATCH] make GenEmail.mailbox_id non-nullable --- app/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 8765fdb0..341e27cd 100644 --- a/app/models.py +++ b/app/models.py @@ -136,6 +136,9 @@ class User(db.Model, ModelMixin, UserMixin): ) # the mailbox used when create random alias + # this field is nullable but in practice, it's always set + # it cannot be set to non-nullable though + # as this will create foreign key cycle between User and Mailbox default_mailbox_id = db.Column( db.ForeignKey("mailbox.id"), nullable=True, default=None ) @@ -543,7 +546,7 @@ class GenEmail(db.Model, ModelMixin): # an alias can be owned by another mailbox mailbox_id = db.Column( - db.ForeignKey("mailbox.id", ondelete="cascade"), nullable=True, default=None + db.ForeignKey("mailbox.id", ondelete="cascade"), nullable=False ) user = db.relationship(User)