MediumBlob in Laravel database schema
Asked Answered
P

3

25

How can I create a Mediumblob within the Laravel schema builder ?

In the docs it says :

$table->binary('data'); // BLOB equivalent to the table

But I need a MediumBlob otherwise the images get truncated at 64K; we are running MySQL.

I know that Laravel's schema builder is DB agnostic, but is there a way to avoid the "native way" and if not how can i create a Mediumblob column ?

Preston answered 20/11, 2013 at 7:13 Comment(1)
If you are using InnoDB engine, it should be 256k at least. Documentation about storage: dev.mysql.com/doc/refman/5.7/en/… .Syntax
G
1

Starting from Laravel 11.x you can now create a longer (or shorter) BLOB with this statement.

I tested this on Laravel 10.x, and it works just fine. Probably need to test in previous versions, but as this is a SQL statement, not a Laravel specific behavior, it must work.

$table->mediumText('data')->charset('binary'); // MEDIUMBLOB
Gaitskell answered 30/7, 2024 at 15:34 Comment(0)
C
57

You can't.

This issue suggests using raw queries to create such columns, so you should do something like this in your migration file :

Schema::create("<table name>", function($table) {
    // here you do all columns supported by the schema builder
});

// once the table is created use a raw query to ALTER it and add the MEDIUMBLOB
DB::statement("ALTER TABLE <table name> ADD <column name> MEDIUMBLOB");
Casta answered 20/11, 2013 at 15:17 Comment(2)
Have you created the issue? you the number? I could find itBernardobernarr
user2629998 links to an issueSubtile
G
1

Starting from Laravel 11.x you can now create a longer (or shorter) BLOB with this statement.

I tested this on Laravel 10.x, and it works just fine. Probably need to test in previous versions, but as this is a SQL statement, not a Laravel specific behavior, it must work.

$table->mediumText('data')->charset('binary'); // MEDIUMBLOB
Gaitskell answered 30/7, 2024 at 15:34 Comment(0)
M
-3

The field is created but the file can not be inserted. And the following error is caused:

#1118 - Row size too large (> 8126)

Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format BLOB prefix of 768 bytes is stored inline.

Marsden answered 10/2, 2015 at 9:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.