On Tuesday 12 September 2006 10:01, Gábor Farkas wrote:
> hi,
>
> as far as i understand,
>
> when you delete an object in django, it also deletes all the objects
> that reference it.
>
> is there a way to only delete the object, and get an exception if other
> objects reference it?
>

Oh dear, I must have missed this behaviour in the documentaton. Looking at the 
code I see that it is true!

This is a disaster. I've just gone through the process of evaluating various 
frameworks and finally settled on Django (although Turbogears was very 
close). I need to take an existing application and make it available over the 
web. This could cause a swing to something else.

As an example, I have a table (product) that is referenced by 11 other tables 
(booking, history, rates, invoice, payroll, timesheets etc.). Those tables 
contain upwards of 10 million rows in the existing application. I certainly 
don't want those records to be deleted just because (by whatever means) 
someone tried to delete a product!!

This is only one example, the existing app has many such relationships.

I have delete restrict set on the foreign keys, but that will now be ignored.

I don't really want to write a check on all 11 tables to see if records exist 
before I try to delete the product, it can be VERY inefficient. It also means 
that I will have to change that part of the code if I invent another table 
that references product. This is also error prone (I, or another developer 
might forget to update the pre-delete checks).

This appears though, to be the only way, aside from hacking the Django source, 
to do the right thing here.

I also wouldn't really want Django to manually check all the dependent tables 
either. I would prefer it to just try and delete the record I had told it to 
and handle the error if it could not. I would certainly be prepared to handle 
the error myself as it is far preferable to manually checking all dependent 
tables pre-delete.

A simple "don't do ANY dependency checking at all, just (try to) delete this 
record" option seems the simplest way to go and by far the most efficient in 
any database that supports the full foreign key behaviour.

I realise of course that Django also has to compensate for inadequate 
databases as well. So an option like the above which is only available if the 
database backend says cascade/restrict/set null foreign keys are implemented 
makes sense.

If I stick with the current plan I suspect I will hack the sources to simply 
NOT try to follow the dependencies on deleting a record and handle any 
resulting error.

If (when?) I become more confident with Django I may attempt a better solution 
and patch.

Any ideas on how to get a simple option in Django to do this sooner?

Regards,
Gary.

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