在Laravel 5.6中播种数据库时出现Illuminate \ Database \ QueryException错误

时间:2018-05-09 04:05:37

标签: php laravel

我现在已经试图解决这个问题差不多2天了。所以,我有一个这样的播种机:

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call([
            'RolesTableSeeder',
            'UserTableSeeder',
            'DevelopersTableSeeder',
            'ESRBRatingTableSeeder',
            'GameGenreTableSeeder',
            'ManufacturerTableSeeder',
            'PlatformsTableSeeder',
            'PublishersTableSeeder',
            'GamesTableSeeder',
            'CommunitiesTableSeeder'
        ]);
    }
}

但是,当我使用php artisan db:seed运行它时,我收到以下错误:

Illuminate\Database\QueryException  : SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field (SQL: insert into `games` (`title`, `description`, `platform`, `ESRBRating`, `developer`, `publisher`, `genre`) values (Pokemon Sun, Pokemon Sun version for the Nintendo 3DS, 4, 1, 1, 1, 4))

我已确定在GamesTableSeeder文件中触发了该问题,如下所示:

public function run()
{

    $platform = Platform::where('name', '=', 'Nintendo 3DS')->first(); 
    $esrb = EsrbRating::where('rating', '=', 'E')->first(); 
    $dev = Developer::where('name', '=', 'GameFreak')->first(); 
    $pub = Publisher::where("name", "Nintendo")->first(); 
    $genre = GameGenre::where('genre', 'Role-Playing')->first(); 

    DB::table('games')->insert([
        'title' => 'Pokemon Sun',
        'description' => "Pokemon Sun version for the Nintendo 3DS",
        'release_date' => new Carbon(),
        'minimum_players' => 1,
        'maximum_players' => 4,
        'platform' => $platform->id,
        'ESRBRating' => $esrb->id,
        'developer' => $dev->id,
        'publisher' => $pub->id,
        'genre' => $genre->id,
        'created_at' => new Carbon()
    ]);
}

如您所见,此表有一些引用不同表的外键。我检查了其他播种机的结果,看看是否有任何导致错误的结果。但是,它们似乎都有效。

我很感激任何帮助,因为这件小事已经让我头疼。它可能是一些可笑的愚蠢行为导致它我只是没有注意到。

以下是该表的迁移。

Schema::create('games', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title')->unique(); 
            $table->multilineString('description'); 
            $table->datetime('release_date')->nullable(); 
            $table->integer('minimum_players')->unsigned()->default(1); 
            $table->integer('maximum_players')->unsigned()->default(1); 
            $table->timestamps();
            $table->softDeletes(); 
        });

这里是添加外键的地方:

Schema::table('games', function(Blueprint $table){
            $table->integer('platform')->unsigned(); 
            $table->integer('ESRBRating')->unsigned(); 
            $table->integer('developer')->unsigned(); 
            $table->integer('publisher')->unsigned();
            $table->integer('genre')->unsigned(); 

            $table->foreign('platform')->references('id')->on('platforms'); 
            $table->foreign('ESRBRating')->references('id')->on('esrb_ratings'); 
            $table->foreign('developer')->references('id')->on('developers'); 
            $table->foreign('publisher')->references('id')->on('publishers'); 
            $table->foreign('genre')->references('id')->on('game_genres'); 
        }); 

1 个答案:

答案 0 :(得分:1)

我认为字段description数据类型存在问题,即multilineString,用于存储几何点,而不是字符串。请将说明字段更新为:

$table->text('description');表架构中的

games。您可以为它创建一个新的迁移:

Schema::table('games', function (Blueprint $table) {
    $table->text('description')->change();
});

运行它然后再次运行播种机。