And if you change the order?
If the foreign key references a model defined later?

Gergely

On márc. 7, 11:40, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, Mar 7, 2011 at 10:04 AM, Gergely <gergely...@gmail.com> wrote:
> > Ok, lets concentrate 1 question at a time.
>
> > 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.
> > DB engine: sqlite. Django version: 1.2.4
>
> > 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,
> >  )
>
> > Best regards,
> > Gergely
>
> Use a better SQL engine. This is Django 1.2.5 + postgresql:
>
> class Series(models.Model):
>   pass
>
> class Episode(models.Model):
>   series = models.ForeignKey('Series',)
>
> CREATE TABLE "media_episode" (
>     "id" serial NOT NULL PRIMARY KEY,
>     "series_id" integer NOT NULL REFERENCES "media_series" ("id")
> DEFERRABLE INITIALLY DEFERRED
> )
>
> Cheers
>
> Tom

-- 
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