Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get Rails to use the LONGBLOB column in mysql?

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?

like image 605
readonly Avatar asked Feb 23 '09 21:02

readonly


People also ask

What is the use of Longblob in MySQL?

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.

What is SQL Longblob?

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.

How does MySQL store BLOBs?

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.


1 Answers

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
like image 106
Michael Glenn Avatar answered Oct 09 '22 01:10

Michael Glenn