Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panthro's avatar

TinyInt - specify size?

If I'm using a tinyint to store 1 or 0. Do I also need to specify it's size as 1?

For example:

$table->tinyInteger('published');

or

$table->tinyInteger('published', 1);

Which should I use?

0 likes
3 replies
LaryAI's avatar
Level 58

No, you do not need to specify the size of a tinyint column when using Laravel's schema builder. The default size for a tinyint column is 1. Therefore, you can simply use the following code to create a tinyint column:

$table->tinyInteger('published');

Specifying the size as 1 is redundant and unnecessary.

tykus's avatar

The second argument to the integer column types is a boolean to specify if it is auto-incrementing. You do not need to specify size.

Tray2's avatar
Tray2
Best Answer
Level 73

A tiny int has the max value of 127 or unsigned of 255, and it uses one byte of space.

You can't give it a size like you can a char or varchar column, this goes for all of the integer datatypes in MySQL.

3 likes

Please or to participate in this conversation.