Hello,
I'm trying to find an answer to an old question that is why I'm
forwarding this old message.
I tried to find the documentation of this change but couldn't.
Could you please help me?
I would like to find out:
 - why is only one foreign key generated in the intermediary join
table?
 - can I influence the sql generation to have both foreign keys
(without specifying my own join table) ?

There is a similar behaviour at simple foreign keys:
If you define the referenced model later and use "lazy" relationship
in the foreign key field (with the name of the model instead of the
model itself) than in the generated sql you will not find the
"REFERENCES" part of the foreign key definition.
Example:

Model:
class Book(models.Model):
    publisher = models.ForeignKey("Publisher")

class Publisher(models.Model):

Generated sql:
CREATE TABLE "books_book" (
    "id" integer NOT NULL PRIMARY KEY,
    "publisher_id" integer NOT NULL,
)

Sorry if these are stupid questions but I would like to understand it
completely.

Regards,
Gergely

---------- Forwarded message ----------
From: Russell Keith-Magee <russ...@keith-magee.com>
Date: 2010 aug. 9, 01:06
Subject: SQL generated for ManyToManyField is incorrect with Django
1.2.1
To: Django users


On Mon, Aug 9, 2010 at 7:28 AM, Ersin Er <ersin...@gmail.com> wrote:
> Hi,

> I was just trying the sample code from the Django Book 2nd Edition but
> the generated SQL script for the Books models are not correct.

> The Model code:

>http://dpaste.com/226416/

> The generated SQL script for sqlite:

>http://dpaste.com/226417/

> What's missing in the generated script is
> 'REFERENCES "books_book" ("id")'
> for the "book_id" field
> in the "books_book_authors" table. (The code listing in the book has
> it.)

> Am I missing something or Django 1.2.1 just generates incorrect
> script?

The SQL generated by Django 1.2.1 isn't incorrect - it's just
different. Django 1.2 introduced a number of internal changes to the
way many-to-many fields were represented; as a result, the output SQL
has changed slightly. The output described by the Django Book is out
of date, but not in any way that matters at a functional level -- the
public API for using m2m fields remains unchanged.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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=en.

Reply via email to