Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Blob Model Field

How do you store a "blob" of binary data using Django's ORM, with a PostgreSQL backend? Yes, I know Django frowns upon that sort of thing, and yes, I know they prefer you use the ImageField or FileField for that, but suffice it to say, that's impractical for my application.

I've tried hacking it by using a TextField, but I get occassional errors when my binary data doesn't strictly confirm to the models encoding type, which is unicode by default. e.g.

psycopg2.DataError: invalid byte sequence for encoding "UTF8": 0xe22665 
like image 772
Cerin Avatar asked Feb 06 '11 18:02

Cerin


1 Answers

If you're using Django >= 1.6, there's a BinaryField

like image 198
Sarah Messer Avatar answered Oct 06 '22 19:10

Sarah Messer