Home  >  Q&A  >  body text

What is the difference between Text and LongText in Laravel migration?

The migration file sections are listed below:

Schema::create('samples', function (Blueprint $table) {
        $table->id();
        $table->text('title1');
        $table->longText('title2');
        $table->timestamps();
    });


P粉268284930P粉268284930369 days ago672

reply all(2)I'll reply

  • P粉523335026

    P粉5233350262023-11-09 15:20:48

    This has nothing to do with Laravel migrations, but rather the data type of the table column, which depends on the size of the text string.

    TINYTEXT: 255 characters - 255 B

    TINYTEXT The data object is the smallest of the TEXT series and is designed to efficiently store short message strings. This type can store up to 255 bytes (expressed as 2^8 -1) or 255 characters and requires 1 byte of overhead. This object can be used to store things like short snippets, URL links, and other shorter objects. TINYTEXT is preferred over VARCHAR when storing data that is less than 255 characters long and is not of consistent length and does not need to be used for sorting criteria.

    Text: 65,535 characters - 64 KB

    The standard TEXT data object is sufficient to handle typical long-form text content. TEXT The maximum size of a data object is 64 KB (expressed as 2^16 -1) or 65,535 characters, requiring 2 bytes of overhead. It's large enough to hold text like an article, but not large enough to hold the text of an entire book.

    MEDIUMTEXT: 16,777,215 characters - 16 MB

    MEDIUMTEXT Data objects are useful for storing larger text strings such as white papers, books, and code backups. 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.

    Long text: 4,294,967,295 characters - 4 GB

    LONGTEXT Data object is used for extreme text string storage use cases. This is a viable option when the MEDIUMTEXT object is not large enough. Computer programs and applications often achieve text lengths in the LONGTEXT range. These data objects can be up to 4 GB in size (expressed as 2^32 -1), store up to 4,294,967,295 characters, and require 4 bytes of overhead storage

    Please note that the number of characters that can be stored in a column depends on the character encoding.

    reply
    0
  • P粉107772015

    P粉1077720152023-11-09 13:34:15

    Text can handle up to 65,535 characters

    Long text can handle up to 4,294,967,295 characters

    reply
    0
  • Cancelreply