gothinkster / flask-realworld-example-app

Exemplary real world JSON API built with Flask (Python)
https://realworld.io/
MIT License
897 stars 308 forks source link

Fix unique constraint on userprofile.user_id #29

Closed Willis0826 closed 1 year ago

Willis0826 commented 4 years ago

I performed the database migration with postgres 9.6.6, and faced to the error :

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidForeignKey) there is no unique constraint matching given keys for referenced table "userprofile"
 [SQL: '\nCREATE TABLE followers_assoc (\n\tfollower INTEGER, \n\tfollowed_by INTEGER, \n\tFOREIGN KEY(followed_by) REFERENCES userprofile (user_id), \n\tFOREIGN KEY(follower) REFERENCES userprofile (user_id)\n)\n\n']

After added the unique constraint to userprofile.user_id, the migration can be performed successfully.

Kyle-Verhoog commented 4 years ago

Also had this problem! Thanks @Willis0826 for providing a quick fix. Would like to see this get merged 🙂

maateen commented 4 years ago

+1 for this PR.

genchilu commented 3 years ago

Also had this problem!

cool21540125 commented 3 years ago

There's no problem when using SQLite, but the same problem when using PostgreSQL 9, 11, 12. Willing to see this get merged.

Willis0826 commented 3 years ago

@mohamed-aziz Hi, I would like to ask for your review for this fix : ) thanks!