The migration file portion is listed below:
Schema::create('samples', function (Blueprint $table) {
$table->id();
$table->text('title1');
$table->longText('title2');
$table->timestamps();
});
CodePudding user response:
Text can handle up to 65,535 characters
Long text can handle up to 4,294,967,295 characters
CodePudding user response:
This is not related to Laravel migration rather its the datatype of a table column which depends on the size of your text string.
TINYTEXT: 255 characters - 255 B
The TINYTEXT
data object is the smallest of the TEXT
family and is built to efficiently store short information strings. This type can store up to 255 bytes (expressed as 2^8 -1) or 255 characters and requires a 1 byte overhead. This object can be used to store things like short summaries, URL links, and other shorter objects. TINYTEXT
shines over VARCHAR
when storing data that’s under 255 characters with an inconsistent length and no need to be used for sorting criteria.
TEXT: 65,535 characters - 64 KB
The standard TEXT
data object is sufficiently capable of handling typical long-form text content. TEXT
data objects top out at 64 KB (expressed as 2^16 -1) or 65,535 characters and requires a 2 byte overhead. It is sufficiently large enough to hold text for something like an article, but would not be sufficient for holding the text of an entire book.
MEDIUMTEXT: 16,777,215 characters - 16 MB
The MEDIUMTEXT
data object is useful for storing larger text strings like white papers, books, and code backup. These data objects can be as large as 16 MB (expressed as 2^24 -1) or 16,777,215 characters and require 3 bytes of overhead storage.
LONGTEXT: 4,294,967,295 characters - 4 GB
The LONGTEXT
data object is for use in extreme text string storage use cases. It is a viable option when the MEDIUMTEXT
object is not big enough. Computer programs and applications often reach text lengths in the LONGTEXT
range. These data objects can be as large as 4 GB (expressed as 2^32 -1) and store up to 4,294,967,295 characters with 4 bytes of overhead storage
Note that the number of characters that can be stored in your column will depend on the character encoding.