du6029076877
2017-04-07 04:09
浏览 42
已采纳

数据库播种器找不到Laravel 5.2的类

When running php artisan migrate --seed, this error appears:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'CreateCharactersTable' not found. 

Here is that that class:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class CharacterSeeder extends Seeder
{
    public function run()
    {
        DB::table('characters')->delete();

        DB::table('characters')->insert([
            'user_id'   => 999,
            'name'      => 'Susan Strong',
            'race'      => 'orc',
            'class'     => 'assassin',
            'image_location'    => null,
            'combat_level'      => '0',
            'base_str'  => 6,
            'base_int'  => 4,
            'base_apt'  => 5,
            'mod_str'   => 9,
            'mod_int'   => 5,
            'mod_apt'   => 7,
            'xp_str'    => 1,
            'xp_int'    => 2,
            'xp_apt'    => 1,
            'is_bot'    => 1,
            'created_at'=> '2017-04-02 17:53:02',
            'updated_at'=> '2017-04-02 17:53:02'
        ]);



        DB::table('characters')->insert([
            'user_id'   => 4,
            'name'      => 'Chale',
            'race'      => 'elf',
            'class'     => 'scholar',
            'image_location'    => null,
            'combat_level'      => '0',
            'base_str'  => 3,
            'base_int'  => 7,
            'base_apt'  => 5,
            'mod_str'   => 6,
            'mod_int'   => 10,
            'mod_apt'   => 6,
            'xp_str'    => 1,
            'xp_int'    => 2,
            'xp_apt'    => 1,
            'is_bot'    => 1,
            'created_at'=> '2017-04-02 17:53:02',
            'updated_at'=> '2017-04-02 17:53:
    }
}

?>

and the seeder:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Database\Seeds\CharacterSeeder;
use Database\Seeds\ClassesTableSeeder;
use Database\Seeds\RacesTableSeeder;
use Database\Seeds\UserTableSeeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UserTableSeeder::class);
        $this->call(CharacterSeeder::class);
        $this->call(RacesTableSeeder::class);
        $this->call(ClassesTableSeeder::class);
    }
}

Running composer dumpautoload passes but does not remove the error. When it was only two seeders, User and Character, it ran well. Despite looking over the new seeders again and again, I cannot determine the error involved.

Any suggestions to get the seeder to run?

Thank you.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • douzuo0711 2017-04-07 04:19
    最佳回答

    You've imported all your seeders from a namespace, but they aren't in a namespace.

    use Database\Seeds\CharacterSeeder;
    use Database\Seeds\ClassesTableSeeder;
    use Database\Seeds\RacesTableSeeder;
    use Database\Seeds\UserTableSeeder;
    

    Just remove those lines and you should be good to go.

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题