Open awgymer opened 6 years ago
Hi @datchpenguin, thanks for this.
Django does depend on an id
field existing. This can be in a couple of ways:
primary_key=True
- this will map .id
to that fieldid
field in your view SQL that Django can use to uniquely identify1 AS id
in your SQL if you're not interested in the ID fieldUsually, it's considered good to determine a primary key for your view so you can look it up, in which case, 1 or 2 would be needed. If you never use a primary key, then just do 3 and that should work fine for most cases.
Thanks for the speedy reply.
Yes, I expected (1) was going to be the solution but I'm clearly too used to letting Django create an automatic id
field for my models.
Hi @datchpenguin no worries. If you'd like to open a PR to update the README, I'd be more than happy to include the information :)
I am trying to use a
MaterializedView
to hold some aggregated queries from one of my model tables. Everything seems fine, however when I try to use the result like a queryset callingMyView.objects.all()
I get the errorcolumn per_machine.id does not exist
. It seems that django expects anid
column to always be present but that unlike a normal model, andAutoField
isn't assigned by default. Is this just the expected behaviour and if so is the intention that one should specify an explicitid
column or am I simply misusing the resulting queryset by callingobjects.all()
?