我正在使用Laravel 5.3,我已经设置了我的生产服务器.所有数据库迁移都已使用以下数据库配置创建:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
But now, some of my users had reported that they get an error when they try to save a form that has emoji ? icons in them. After searching I found out that I need to set the mysql charset to utf8mb4
for this to work so my config should have been something like this instead:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
因为这是在生产服务器中,所以我不能执行migrate:refresh
.所以我的问题是:
- 如何将使用laravel迁移创建的现有数据库更改为使用
utf8mb4
而不是utf8
,并在相同的基础上更新laravel?有更简单的方法吗? - If the above is possible, am I better off setting
utf8mb4
for all tables or only use that for the 2 table columns where I will really be using emoji.
谢谢你的帮助.