On Sun, May 11, 2008 at 4:36 PM, Николай Бульба <[EMAIL PROTECTED]> wrote:
>
>
> 2008/5/11 Peter Melvyn <[EMAIL PROTECTED]>:
> >
> > On 5/11/08, phactor <[EMAIL PROTECTED]> wrote:
> >
> > > no keyword REFERENCES. Where is it?
> >
> > AFAIK, SQLite engine 'per se' does not support reference integrity, see:
> >
> > - http://www.sqlite.org/lang_createtable.html
> > - http://www.sqlite.org/omitted.html
>
> Well, so why on http://www.djangoproject.com/documentation/tutorial01/
> phrase
> "The foreign key relationship is made explicit by a REFERENCES statement."
> can be found?
>
> In steps I wrote earlier you can see REFERENSES keyword is appeared for
> poll_id of test_choice, but not for field_id of test_p. What the difference?
The difference is the order in which the models were processed. In the
first example 'p' has a relation on 't', but the table for 't' is
created after 'p'.
If you use a database other than SQLite, the output of `sql test` will
include a statement something like:
ALTER TABLE "test_p" ADD CONSTRAINT field_id_refs_id_ea8731f FOREIGN
KEY ("field_id") REFERENCES "test_t" ("id") DEFERRABLE INITIALLY
DEFERRED;
This command is issued after the CREATE TABLE command for ''t', and
modifies the table for 'p' to add the reference to the table for 't'
that didn't exist at the time 'p' was created. In the second example,
the table for 'choice' is created after the table for 'poll', so the
REFERENCES clause can be included at time of table creation.
SQLite is, as the name suggests, a 'database lite'. It allows (but
essentially ignores) REFERENCES statements during model defintion, but
it doesn't allow ALTER TABLE statements to add REFERENCES clauses.
This point is glossed over in the tutorial because for beginning
users, it is unnecessary detail. REFERENCES clauses will always be
created as required. It just happens that when using SQLite, they
aren't.
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---