On 10/5/06, Greg Plesur <[EMAIL PROTECTED]> wrote:
>
> Waylan Limberg wrote:
> >> Do any of you know if there's a way to tell Django to specify "on
> > cascade delete" for foreign key references, when it creates DB tables?

Django doesn't use ON DELETE CASCADE in its table definitions, due to
some database backends not fully supporting the operation. To
compensate, when you delete an object through the Django ORM, it
calculates the dependent objects, and deletes them as well.

However, if you _really_ want to have ON DELETE CASCADE in your model,
your best bet is to use the custom SQL handlers. If you create an
'sql' directory in your models directory, and put a file called
'mymodel.sql' in that directory (where mymodel is the name of your
model), the contents of that file will be executed on the database
when syncdb installs the model.

If you put some ALTER statements in the file, you can add the cascade
directive, or any other table modifications/triggers you want to the
table after it has been created.

> > I don't believe you can. However, you can use sql or sqlall [1] to
> > output the table creation sql to a file for editing.  For example:
> >
> > manage.py sqlall myapp > myapp.sql
>
> I was looking at this, but:  Does anyone know why "manage.py sqlall"
> rearranges the order of the table-creates from what's in the models?
>
> I can't find the reason for the new ordering; it looks kind of random,
> and it causes the table-creates to fail because of foreign key constraints.

It isn't random - it's hashtable order. There's no particular reason
for it, other than the fact that we need to have a dictionary to store
the models.

However, you shouldn't be having any problems with foreign key
constraints. The model creation process should be able to identify and
avoid any problems with forward declared foreign key constraints.

That said, I am aware (and am working on fixing) a slight problem with
install/sqlall dealing with multiple applications; specificially if
you try to run:

manage.py sqlall app1 app2
or
manage.py install app1 app2

and app1 has a dependency on app2, sqlall reports problems with model
creation. manage.py syncdb doesn't have this problem.

Is this the problem you are experiencing? If not, can you provide more
details (backend, models etc)

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to