Laravel Framework 5.5.43
Server version Mysql 5.7.23-0ubuntu0.18.04.1
Я использую сеялку.
DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(UsersTableSeeder::class);
// factory(App\User::class, 50)->create();
}
}
UserFactory.php
$factory->define(App\User::class, function (Faker $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});
$factory->defineAs(App\User::class, 'admin',function (Faker $faker) {
return [
'name' => 'user',
'email' => 'user@gmail.com',
'password' => bcrypt('123456'),
'remember_token' => str_random(10),
];
});
$factory->defineAs(App\Article::class, 'admin',function (Faker $faker) {
return [
'title' => '_title',
'slug' => '_slug',
'description_short' => '_description_short',
'description' => '_description',
'meta_title'=>'',
'meta_description'=>'',
'meta_keyword'=>'',
'published'=>'1',
'viewed'=>2,
];
});
UsersTableSeeder.php
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
factory(App\User::class, 'admin', 1)->create()->each(function ($user){
$user->user_article()->save(factory(App\Article::class, 'admin')->make());
});
}
}
2018_06_08_112606_create_articles_table.php
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('slug')->unique();
$table->text('description_short')->nullable();
$table->text('description')->nullable();
$table->string('image')->nullable();
$table->boolean('image_show')->nullable();
$table->string('meta_title')->nullable();
$table->string('meta_description')->nullable();
$table->string('meta_keyword')->nullable();
$table->boolean('published');
$table->integer('viewed')->nullable();
$table->integer('created_by')->nullable();
$table->integer('modified_by')->nullable();
$table->timestamps();
});
}
2014_10_12_000000_create_users_table.php
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
Я запускаю команду:
php artisan migrate:refresh --seed
и получите сообщение:
Seeding: UsersTableSeeder
In Connection.php line 664:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1970-01-01 00:00:01' for column 'created_at' at row 1 (SQL: insert into `articles` (`title`, `slug`, `description_short`, `description`,`meta_title`, `meta_description`, `meta_keyword`, `published`, `viewed`,`created_at`, `updated_at`) values (_title, title-1409181309, _description_short, _description, , , , 1, 2, 1970-01-01 00:00:01, 2018-09-14 13:09:45));
In Connection.php line 458:
SQLSTATE[22007]: Invalid datetime format: 1292 **Incorrect datetime value: '1970-01-01 00:00:01' for column 'created_at' at row 1
Я не могу понять, почему я получаю значение 1970-01-01 00:00:01 для столбца «made_at». И как я могу это исправить?
Кроме того, почему я получаю правильное значение 2018-09-14 13:09:45 для столбца updated_at.
Кроме того, после указанной выше команды запуска вставьте запись в таблицу пользователей.
Я думаю, что это странно. Любая идея? Спасибо.