pythonmysqlsqlalchemy

SqlAlchemy: How to make a LONGBLOB column in mysql?


Using sqlalchemy with mysql-python, I have this table:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Index, LargeBinary
Base = declarative_base()
class Tbl(Base):
     __tablename__ = 'tbl'
     ...
     data = Column(LargeBinary())

However, when I create this table (using Base.metadata.create_all(engine)), and then DESCRIBE tbl; in mysql, I get this:

mysql> describe logs;
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
...
| data         | blob        | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+

Expected result: I want this to be a longblob in mysql, and not a blob which is limited to 64kB


Solution

  • Using:

    data = Column(LargeBinary(length=(2**32)-1))
    

    Causes LargeBinary to create a longblob type