2
votes

I want to create a table like so -

CREATE TABLE trial_xml (
id int(11) DEFAULT NULL,
pid int(11) DEFAULT NULL,
sid varchar(256) CHARACTER SET utf8 NOT NULL,
data blob,
PRIMARY KEY (soid), KEY suid_index (suid) ) ENGINE=MyISAM DEFAULT CHARSET=latin1

my question is how do I set "data" field as "blob" in django's models.py ??

I mean what's the syntax?

UPDATE: I dont want to set data field as longtext. I want only blob datafield.

3

3 Answers

1
votes

Django's ORM has no field for binary large objects. Either use something like a FileField, or search for candidate field classes using a search engine.

2
votes

I have been using this simple field for 'mysql' backend, you can modify it for other backends

class BlobField(models.Field):
    description = "Blob"
    def db_type(self):
        return 'blob'
1
votes

For what it's worth, Django now has a proper BinaryField. It was added on Dec 13, 2012.

https://github.com/django/django/commit/8ee1eddb7e148de89aebde9e68da495633fc1ec9

The relevant documentation is available here: https://docs.djangoproject.com/en/1.8/ref/models/fields/#binaryfield