V
V
Vladimir Rudomakha2018-10-19 17:11:10
SQL
Vladimir Rudomakha, 2018-10-19 17:11:10

How to ensure data uniqueness in SQLAlchemy?

There is a table:

PostVoice(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'),nullable=False)
    blogpost_id = db.Column(db.Integer, db.ForeignKey('blog_post.id'),nullable=False)
    value = db.Column(db.Enum(VoiceEnum),nullable=False)

How to ensure that a user can only vote once. That is, if the user has already gone for this post, his voice was changed, and another record of his voice was not created.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question