I have an app with several django/python data models and associated postgres database tables. In this case the important ones are User
and Feed
.
I need to create a one to one relationship between a column in my Feed model and items in my User model. If I were starting the app from scratch I would simply define a user
property in my Feed
models as such:
from django.contrib.auth.models import User
class Feed(models.Model):
...
user = models.OneToOneField(User)
Of course, being that my app is already functioning, I need to modify my database tables with SQL commands in accordance with my django/python data model changes.
My question is, what SQL commands do need to create a OneToOneField
? I've used the documentation here: http://www.djangobook.com/en/2.0/chapter10.html as a guide when doing SQL commands in the past. But I'm concerned that I'm gonna screw something up when it comes to OneToOneFields.
The django manage.py sqlall
command tells me that I need a column that looks like:
"user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED