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
SQLAlchemy supports MySQL starting with version 5.0. 2 through modern releases, as well as all modern versions of MariaDB.
Description. A BLOB column with a maximum length of 4,294,967,295 bytes or 4GB (232 - 1). The effective maximum length of LONGBLOB columns depends on the configured maximum packet size in the client/server protocol and available memory.
From SQLAlchemy docs: nullable – If set to the default of True, indicates the column will be rendered as allowing NULL, else it's rendered as NOT NULL. This parameter is only used when issuing CREATE TABLE statements.
PickleType. Holds Python objects, which are serialized using pickle. SchemaType. Mark a type as possibly requiring schema-level DDL for usage.
Using:
data = Column(LargeBinary(length=(2**32)-1))
Causes LargeBinary to create a longblob
type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With