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条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探