make GenEmail.mailbox_id non-nullable

This commit is contained in:
Son NK 2020-03-05 17:00:43 +01:00
parent cb3ea63066
commit faa82e7b5a

View file

@ -136,6 +136,9 @@ class User(db.Model, ModelMixin, UserMixin):
) )
# the mailbox used when create random alias # 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( default_mailbox_id = db.Column(
db.ForeignKey("mailbox.id"), nullable=True, default=None 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 # an alias can be owned by another mailbox
mailbox_id = db.Column( 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) user = db.relationship(User)