How do i correct this ?

I created a database that allows other users to like and comment on posts. The "like" button and "commnet" button are different tables respectively with both having a ForeignKey relationship to the Posts. Everything is working fine is multiple users liked a post at different time, but if multiple users clicked the 'like" button at the same time, it'll be counted as 1. Is something wrong with the foreignkey relationship that exist between likes and post or something? I'm using SQLite and Python( not django ) in the backend

11/15/2019 9:29:14 AM

Mirielle🐶 [Inactive]

9 Answers

New Answer


Sounds like some sort of synchronization issue. When you update the number of likes, how do you determine the new value? Is it based on the number of current likes that the user is seeing? I think it should work if the increment is done directly in the sql update statement, like so UPDATE likes SET count = count + 1 WHERE post_id =...


Thanks, i figured out where the bug is .. I'm using an "if-elif" statement then forgot to add a new condition to the else statement. So i'm using "if users-id == post.like.id ": increment elif users-id == post.like.id ": increment else: increment increment is a newly created and not directly from the db


Ok. Glad you got sorted. It's an area of interest for me at the moment. PHP and SQL. Just figured out the other week how to update user logins with timestamps. So, I'm learning as I go.


Something you might find useful in the future. It's about timestamps, even down to microseconds. https://stackoverflow.com/questions/14461851/how-to-have-an-automatic-timestamp-in-sqlite


Xyenia 🦉 , there's an sql table called "User"..then whenever i imported that to python, it counts as one but xd that isn't the problem as i'm able to filter from there. The conditional statement is wrong


Are you recording a timestamp with each recorded click? Do you have entropy or a unique identifier to distinguish the clicks?


Use transactions


what is sql


hay what are you dowing