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

时间:2017-04-07 04:09:17

标签: php laravel artisan

运行php artisan migrate --seed时,会出现此错误:

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

以下是该课程:

<?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:
    }
}

?>

和播种机:

<?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);
    }
}

正在运行composer dumpautoload次但未删除错误。当只有两个播种者,用户和角色时,它运行良好。尽管一次又一次地查看新的播种机,我无法确定所涉及的错误。

有什么建议让播种机运行?

谢谢。

3 个答案:

答案 0 :(得分:3)

如果您手动添加了播种机文件,则应首先运行composer dump-autoload。这将为您重新生成autoload_classmap.php文件,有关详细信息,请参阅Composer Dump-Autoload

答案 1 :(得分:0)

您已从命名空间导入了所有播种机,但它们不在命名空间中。

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

只需移除这些线条就可以了。

答案 2 :(得分:0)

'CreateCharactersTable'应该是Migration。您需要检查此迁移文件或类是否存在。

如果你只使用播种机。你可以执行 php artisan db:seed