Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This database doesn't support filtering on non-primary key ForeignKey fields. #76

Open
jeffsgraham opened this issue Jul 19, 2016 · 0 comments

Comments

@jeffsgraham
Copy link

I apologize if this is the wrong place to post this, but I thought I would mention it in case others were having the same trouble I was. Also, so I can get feedback if I am missing something or otherwise committing a heinous sin.

My project using django-nonrel and djangotoolbox 1.8.0 with a MongoDB 2.6 data store raises an exception "This database doesn't support filtering on non-primary key ForeignKey fields." when I try to (surprise) filter on non-primary FK fields.

It appears to be a true statement, I cannot find any documentation regarding MongoDB supporting relations between collections on anything other than a primary key. However, just because it isn't supported doesn't mean it doesn't work. In fact it works exactly as I expected it to. Removing the conditional that raises this exception in lines 233-234 of basecompiler.py seems to result in proper filtering behavior from MongoDB. This saved me from writing custom forms for all my admin models.

Disclaimer: I have only tested this in the context of my current application, more testing is recommended. Likely the statement in question is there for a reason, a better solution than removing it entirely is likely necessary.

I have attached a patch file detailing the changes I made.
djangotoolbox-basecompiler-1.8.mongo.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant