🦁

❌シーディングは成功するが、テーブルにデータが反映されない

2021/10/06に公開

src/database/seeds/DatabaseSeeder.php

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        //  $this->call(UsersTableSeeder::class);
         $this->call(MusicFilesTableSeeder::class);
    }
}

src/database/seeds/MusicFilesTableSeeder.php

<?php

use Illuminate\Database\Seeder;

class MusicFilesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        [
            'id' => '23',
            'music_file' => 'mp3files/メジャーリーグファンファーレ.mp3',
            'cover_image' => 'images/sample.png',
            'title' => 'seeder test',
            'genre' => 'j-pop',
            'emotions' => 'joy',
            'created_at' => date('Y-m-d H:i:s'),
            'updated_at' => date('Y-m-d H:i:s'),
            'user_id' => '1',
            'uesr_name' => 'seeder test',
        ];
    }
}

/var/www/html/src

# 
# php artisan db:seed
Seeding: MusicFilesTableSeeder
Seeded:  MusicFilesTableSeeder (0 seconds)
Database seeding completed successfully.
# php artisan db:seed --class=MusicFilesTableSeeder
Database seeding completed successfully.
# 

なぜ?

確認できてること

  • MusicFilesTableSeederのスペルは問題なさそう

https://teratail.com/questions/238026

  • DatabaseSeeder.php に使用するシーダーを列挙できてそう

https://teratail.com/questions/293185

Discussion