Reputation: 23427
I am working on an application on Django and google application engine. In my application I have several models with several ReferenceProperty fields. The issue is that if any of the ReferenceProperty field gets deleted it produces a ReferenceProperty related errors in all the other models where it has been used. What I want is, when a field is deleted say a User is deleted, all the fields having User as the ReferenceProperty should still work without any error messages displaying the associated user as unavailable or something like that.
Can someone please suggest how that can be done?
Thanks in advance.
Upvotes: 1
Views: 262
Reputation: 98816
You could also just set a flag, say deleted
, on the entity you're deleting, and then leave it in the datastore. This has the advantage of avoiding all referential integrity problems in the first place, but it comes at the cost of two main disadvantages:
deleted
property set, either by omitting them from the result set or by special casing them somehow.This doesn't really solve your problem at all, but I thought I'd mention it for completeness's sake.
Upvotes: 1
Reputation: 992
Two possible solutions:
Check if the reference still exists, before you access it:
if not obj.reference:
# Referenced entity was deleted
When you delete a model object that may be referenced, query all models that might reference it, and set their reference property to None.
Upvotes: 0
Reputation: 3236
When I have the same problem ago, I could not find a general solution. The only way I found is to do try/except for every reference property. If you find another answer post it here.
Upvotes: 0