开发者

Django models "blob" field

I want to create a table like so -

CREATE TABLE trial_xml (

id int(11) DEFAULT NULL,

pid int(11) DEFAULT开发者_StackOverflow 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.


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'


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜