SQLSTATE [22021]:字符不在保留曲目中

时间:2018-04-22 00:35:37

标签: database laravel postgresql utf-8 seeding

我在播种PGSQL数据库时遇到了这个问题:

   Illuminate\Database\QueryException  : SQLSTATE[22021]: Character not in repertoire: 7 ERROR:  secuencia de bytes no válida para codificación «UTF8»: 0xe3 0x83 0xe2 (SQL: insert into "races" ("name", "public_name", "members", "updated_at", "created_at") values (harp��a, Harpía, 23, 2018-04-21 20:30:20, 2018-04-21 20:30:20) returning "id")

  at C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   PDOException::("SQLSTATE[22021]: Character not in repertoire: 7 ERROR:  secuencia de bytes no válida para codificación «UTF8»: 0xe3 0x83 0xe2")
      C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:330

  2   PDOStatement::execute()
      C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:330

  Please use the argument -v to see more details.

这是我的Seeder的代码:

<?php

use Illuminate\Database\Seeder;
use App\Models\Race;

class RaceTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

      $races = [
        'Humano',
        'Orco',
        'Elfo',
        'Harpía',
        'Enano',
      ];

      for ($i = 0; $i < count($races); $i++) {

        $race_i = utf8_encode($races[$i]);

        $race = Race::create([
          'name' => strtolower($race_i),
          'public_name' => $race_i,
          'members' => mt_rand(10,30),
        ]);

      } // for

    }
}

我的数据库配置:

pgsql database

我的config.database文件配置:

config.database file

这个问题有解决办法吗?我可以找到摆脱这个问题的方法......

修改

我只是注意到一些奇怪的东西。我的数据库中有两条记录:

database records

他们两个都有符号给我带来播种机的问题。也许问题在于播种机逻辑?我正在做与Laravel / Postgresql项目一直一样的事情,所以我找不到为什么我不能用重音标记种子的原因,但我可以使用一个简单的表格存储这种信息。有什么想法吗?

0 个答案:

没有答案