0

how one-to-one field in django reflected in database? I have two model: Neighbor and Neighbor_Info which has one-to-one field connection to Neighbor.

But In the database I don't see any reference field relation between this two table enter image description here

enter image description here

So I wonder how the one-to-one relation reflected on database? (I use postgresql)

Ziqi Liu
  • 2,931
  • 5
  • 31
  • 64
  • This is not a duplicate, but this linked question may provide additional insight: https://stackoverflow.com/questions/19641841/django-difference-between-one-to-one-many-to-one-and-many-to-many – souldeux Nov 01 '17 at 22:52

2 Answers2

2

Your Neighbor_Info model has a OneToOneField to Neighbor.

class Neighbor_Info(models.Model)
    neighbour = models.OneToOneField(Neighbor)
    ...

Therefore your Neighbour_Info database table has a column neighbor_id, which is pictured in your second screenshot.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
0

This may sound stupid but did you remember to migrate?

And secondly on your neighbor info table there is a neighbor_id which should reference reference the id of a neighbor on your neighbor table

Taylor
  • 1,223
  • 1
  • 15
  • 30