So I’ve done some more digging, and the general principles are documented in the Cross-database relations paragraph on the Multiple Databases page.
Briefly, as it relates to your questions here, it is possible to create an environment where, on some databases, it is possible to create something that effectively works as an FK across databases - but it’s not something that Django officially supports. However, since it is possible under the right circumstances, it shouldn’t be something that throws an error.
But, regarding your point #2, I don’t see where you’ve demonstrated that that is what has actually happened. Nothing you’ve described previously indicates that that’s what’s happening in the absence of something previously being loaded / cached.
For example, you mentioned that you used “refresh_from_db”. But, that’s not going to change anything, because the FK you’re retrieving from the database doesn’t change. It’s still the same value, and so it’s not going to change what it’s referring to. Likewise with the get. Without specifying a select_related - and possibly not even then - again, it’s not going to retrieve the related object, which is the object being questioned here.
To gather more information:
- re-run your examples using shell_plus from django-extensions with the --print-sql option
- when you’re looking at objects, don’t just look at the values in the object - look at the id of the object. (I’m not talking about Django’s ID field, I’m referring to the python id function for that model). This will let you know whether or not you’re looking at the same object.
- After you’ve created the situation you’ve described, try performing the
getto a fresh variable to avoid seeing effects due to cacheing.
Through all of this, pay particular attention to the queries being generated.