Reputation: 1239
How can I add tiny integer column using laravel migration to MySQL? I thought this code
$table->addColumn('tinyInteger', 'birth_day', ['lenght' => 2]);
But it creates TINYINT(4) column. I don't know how I can solve this problem. Please don't ask me why a day only, not full date. It is a business logic of the app.
Upvotes: 6
Views: 27688
Reputation: 890
It looks to me like you're spelling "length" wrong, maybe try $table->addColumn('tinyInteger', 'birth_day', ['length' => 2]);
Upvotes: 4
Reputation: 15693
/**
* 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'));
}
This is the tinyInteger() function from Blueprint.php. As you can see it expects a boolean parameter here. It looks like you're trying to add a argument for size. You cannot specify the size of tinyInt in Laravel.
Instead use
$table->tinyInteger('birth_day'); // `birth_day` tinyint(3)
Upvotes: 3
Reputation: 1239
I solve my problem by pure sql
DB::statement("ALTER TABLE `users`
ADD `birth_day` TINYINT(2) DEFAULT NULL AFTER `lastname`");
Upvotes: 2