Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: "Soft" ForeignField without database integrity checks
    text
    copied!<p>I have a Django project that has multiple django "apps". One of them has models to represent data coming from an external source (I do not control this data).</p> <p>I want my other apps to be able to have references to this "external app" but I want to avoid all the fuzz of the database integrity checks. I don't want the db to have any constraints on these "soft foreign keys".</p> <p>Do you know how I can code a custom field that will emulate a real Django ForeignKey without creating a hard constraint on the database?</p> <p>Maybe this already exists, but I didn't have any luck on Google.</p> <p>Thanks in advance for the help :-)</p> <p>NB: I'm aware of the <a href="https://docs.djangoproject.com/en/1.4/ref/contrib/contenttypes/#generic-relations" rel="nofollow noreferrer">generic relations</a> system with the content_types. But I don't want generic relations. I want specific relations to identified models only without hard integrity constraints.</p> <p>EDIT:</p> <p>I found related links:</p> <ul> <li><a href="https://stackoverflow.com/questions/3558907/django-foreignkey-which-does-not-require-referential-integrity">Django ForeignKey which does not require referential integrity?</a></li> <li><a href="https://stackoverflow.com/questions/6788558/understanding-mysql-aka-tricking-foreignkey-relationships-in-django">Understanding / mySQL aka tricking ForeignKey relationships in Django</a></li> </ul> <p>But I didn't find a proper answer to my question. :(</p> <p>EDIT 2012, june 4:</p> <p>I've looked deep into django's code to find what needs to be done, but I think that simply subclassing ForeignKey will not be enough. Could you give me some directions on how to do this?</p> <p>NB: I use South for managing my database schema, so I figure I'll need to do something about that too. But it may be out of the subject here :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload