Because the link table is created after the Bookmarks one that would
be a reference to a non-existant table, if you use the sqlall command
instead you will see that the tables are altered to add the
constraint.

On Jul 1, 1:57 am, KevinTran <[EMAIL PROTECTED]> wrote:
> Hi I'm currently reading Learning Website Development with Django and
> I'm having a problem with models.  Here is my models.py:
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class Link(models.Model):
>     url = models.URLField(unique=True)
>
> class Bookmark(models.Model):
>     title = models.CharField(maxlength=200)
>     link = models.ForeignKey(Link)
>     user = models.ForeignKey(User)
>
> The book says that if I run "python manage.py syncdb" and then "python
> manage.py sql bookmarks" then I should get the following:
>
> BEGIN;
> CREATE TABLE "bookmarks_bookmark" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "title" varchar(200) NOT NULL,
>     "user_id" integer NOT NULL REFERENCES
>       "auth_user" ("id"),
>     "link_id" integer NOT NULL REFERENCES
>       "bookmarks_link" ("id"),
> );
> CREATE TABLE "bookmarks_link" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "url" varchar(200) NOT NULL UNIQUE
> );
> COMMIT;
>
> What I actually get is:
>
> BEGIN;
> CREATE TABLE "bookmarks_bookmark" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "title" varchar(200) NOT NULL,
>     "link_id" integer NOT NULL,
>     "user_id" integer NOT NULL REFERENCES "auth_user" ("id")
> );
> CREATE TABLE "bookmarks_link" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "url" varchar(200) NOT NULL UNIQUE
> );
> COMMIT;
>
> Why does the link_id not get referenced as a foreign key the way the
> user_id does?  I have a feeling that this is very simple, but I can't
> get my head around it.  Thank you.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to