Just because something can be done, does not mean it should be done.

I have always avoided putting large binary files into the DB - why?  
Primarily because the information in them is "dead" - very hard to search 
or filter, which rather defeats the point of using a DB.  Rather leave them 
on disc and add a pointer to each of them.  For one app, I did convert all 
the data in their files (typically Excel or PDF) into "raw text" and stored 
that text in the DB so it was, at least, searchable (but obviously not 
really viewable in that state).
Also, a call like:

ModelWithFileContents.objects.all()

Can be quite overwhelming unless you know what you are doing; rather look 
to extract specific fields that you know you want to display/access.  I 
would imagine that the only time you are going to want to retrieve that 
BLOB (assuming you stick to your current design) is per individual record 
"on request".


On Wednesday, 27 February 2019 03:18:00 UTC+2, Dan Davis wrote:
>
> For the group, the eventual culprit was not complicated.  It is a model 
> with a BinaryField that holds a file's contents. The Django documentation 
> advises against this, but why?   Well, on-premise with big-iron database 
> like Oracle, storing the file in the database is attractive.  So, what's 
> the problem?
>
>       ModelWithFileContents.objects.all()
>
> There you go, even if you are not using the file, its contents will be 
> fetched into memory.
> The solution if it must be at the Django level is to use defer() properly, 
> and add it to the ModelManager.
>
> What I did is to make sure the developer *always* used a database view 
> that doesn't have the binary field for most operations.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b4e09fb6-b426-455d-aa3c-7191da404fc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to