I create migration like this: php artisan make:migration create_categories_table --create categories
Then I add some columns, like:
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 150);
$table->timestamps();
});
and then: php artisan migrate
This creates table categories
, then I insert into categories:
insert into categories
(name)
values
('sport')
This inserts row but created_at
column is null
instead of current timestamp.
What is my mistake?
I did (mysql command): show create table categories
:
CREATE TABLE `categories` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`) )
ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci
which clearly shows that default value for created_at
is NULL. Why?