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
), KEYsuid_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'
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.