I'm trying to write a migration that adds a LONGBLOB column to a table in a MySQL database. I'd like to use LONGBLOB instead of BLOB so that I can store more data in the binary column. The problem is that it adds a BLOB column even though I specify a larger size.
Here's the line I'm using to add the column:
add_column :db_files, :data, :binary, :null => false, :size => 1.megabyte
Am I doing this incorrectly?
LONGBLOB: A binary large object column with a maximum length of 4294967295 (2^32 - 1) bytes, or 4GB in storage. Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value.
LONGBLOB. For BLOBs (Binary Large Objects). Holds up to 4,294,967,295 bytes of data. ENUM(val1, val2, val3, ...) A string object that can have only one value, chosen from a list of possible values.
In MySQL, we can use BLOB datatype to store the files. A BLOB is a binary large object that can hold a variable amount of data. We can represent the files in binary format and then store them in our database. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB.
The following will create a MEDIUMBLOB field. Use 16.megabyte to go to a LONGBLOB.
def self.up
create_table "blob_test", :force => true do |t|
t.column :data, :binary, :limit => 10.megabyte
end
end
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