在 Laravel 迁移中创建一个自定义大小的小整数列

Create a tiny integer column with custom size in Laravel migration

如何使用 laravel 迁移到 MySQL 添加小整数列?我以为这段代码

$table->addColumn('tinyInteger', 'birth_day', ['lenght' => 2]);

但它创建了 TINYINT(4) 列。我不知道如何解决这个问题。请不要问我为什么只有一天,而不是完整的日期。它是应用程序的业务逻辑。

我通过纯sql

解决了我的问题
DB::statement("ALTER TABLE `users` 
ADD `birth_day` TINYINT(2) DEFAULT NULL AFTER `lastname`");
   /**
     * Create a new tiny integer (1-byte) column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
    {
        return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned'));
    }

这是 Blueprint.php 中的 tinyInteger() 函数。如您所见,它需要一个布尔参数。看起来您正在尝试添加大小参数。您不能在 Laravel.

中指定 tinyInt 的大小

改为使用

$table->tinyInteger('birth_day'); // `birth_day` tinyint(3)

我觉得你拼错了“length”,试试看 $table->addColumn('tinyInteger', 'birth_day', ['length' => 2]);