[Answered ]-OneToOneField is not working django

2👍

First of all. If you are using keys you should not use ‘id’ in the name. Django use ‘id’ so then your column name in the database will be ‘user_id_id‘. I think you don’t want this name in your database. It is redundant.

Second thing, you should pass object to the query. Because OneToOneField is related to Login model, you should pass Login object. So try something like this, you have to change your values:

loginDetail = Catcher.objects.get(catcher_id=Login.objects.get(user_id=742))  # you should change only on 'login' and only on 'user'

But you can use join over the models (database tables) also:

loginDetail = Catcher.objects.filter(catcher_id__user_id=742)

And also based on PEP you should not use spaces between name of parameter and equal sign. Write only this: .get(user_id=742)) not .get(user_id =742))

👤Bulva

Leave a comment