Hi there,

I am new to Django and SQL, and I'm putting together my first Django
project.  My project will contain multiple apps, and one app has a
model that I'd like to "One To One" extend with a table in a different
app.  However, it's not behaving how I'd expect, and I can't seem to
find any info addressing my question.

As an example, app1 collects names and app2 collects social security
numbers.  Each name should have exactly one social security number,
and vice versa.

app1.models:
...
class UserName(models.Model):
    name = models.CharField(max_length=60)
...

app2.models:
...
class SocialSecurty(models.Model):
    username = models.OneToOneField('app2.UserName', primary_key=True)
    ssn = CharField(max_length=9)       # no validation - just an
example
...

The problem is that the SQL generated by 'manage.py sqlall app1 app2'
is:
BEGIN;
CREATE TABLE "app1_username" (
    "id" integer NOT NULL PRIMARY KEY
    "name" varchar(60) NOT NULL
)
;
CREATE TABLE "app2_socialsecurity" (
    "username_id" integer NOT NULL PRIMARY KEY,
    "ssn" varchar(9) NOT NULL
)
;
COMMIT;

Now I'm new to SQL, but I was expecting to see a REFERENCE token in
the second table, like this:
...
CREATE TABLE "app2_socialsecurity" (
    "username_id" integer NOT NULL PRIMARY KEY REFERENCES
"app1_username" ("id"),
    "ssn" varchar(9) NOT NULL
)
;
...
I have faith that my Django project will work the way I expect it
without that REFERENCE token, but I'm concerned about performance.
I'm assuming the database will perform better if it's structured with
that reference, instead of some sort of match-up that Django does.
I've tried Foreign Key with unique=True, but it produces the same
issue - no reference.

Am I thinking about this wrong performance wise?  Or does Django
purposely stop my app2 from depending on an app1 table for "loose
coupling" reasons?  Or is it something else?

Thanks for any insight.
Trev

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to