2

I'm using a migration script to create and insert database value using Yii 2's Migration When I migrate, it shows me this error:

*** applying m141125_045122_create_user_table
    > create table {{%user}} ... done (time: 0.009s)
    > insert into {{%user}} ...Exception 'yii\db\Exception' with message 'SQLSTA
TE[HY000]: General error: 1366 Incorrect string value: '\x9A\xD6M\xAE\x02g...' f
or column 'auth_key' at row 1
The SQL being executed was: INSERT INTO `user` (`username`, `password_hash`, `au
th_key`, `email`, `created_at`, `updated_at`) VALUES ('admin', '$2y$13$zKGigop9G
zmAkrfa8FSJIuebOOnNGDMsNuePwniQW60H7vnubaOwC', 'Ü╓M«☻gHt■Sα◄?↕ºo?Xèö▐ É¬=1N↑αï╨+
', 'admin@example.com', NOW(), NOW())'

in C:\Apache24\htdocs\media_avenue\vendor\yiisoft\yii2\db\Schema.php:532

Error Info:
Array
(
    [0] => HY000
    [1] => 1366
    [2] => Incorrect string value: '\x9A\xD6M\xAE\x02g...' for column 'auth_key'
 at row 1
)

This is my migration script:

public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8mb4  COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%user}}', [
            'id' => Schema::TYPE_PK,
            'username' => Schema::TYPE_STRING . ' NOT NULL',
            'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
            'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
            'password_reset_token' => Schema::TYPE_STRING,
            'email' => Schema::TYPE_STRING . ' NOT NULL',
            'role' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',

            'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
            'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
            'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
        ], $tableOptions);

        $this->insert('{{%user}}', [
            'username' => 'admin',
            'password_hash' => Yii::$app->security->generatePasswordHash('admin'),
            'auth_key' => Yii::$app->security->generateRandomKey(),
            'email'=> Yii::$app->params['adminEmail'],
            'created_at'=> new Expression('NOW()'),
            'updated_at'=> new Expression('NOW()'),
        ]);
    }

My MySQL version is 5.6.21.1, I've tried messing up with the encoding by changing it from utf8 to utf8mb4, but it's still not working

what can be the cause of this ? thanks before

Note:

  • If I use XAMPP, I won't get this error.

  • The errors is shown only when I do the manual installation of my MySQL

Edxz
  • 823
  • 2
  • 8
  • 22

1 Answers1