2017-10-09 103 views
0

我想使用修補程序來操縱我的項目的表,所以,我遇到的第一個問題是,我創建了一個utf8編碼的數據庫,之後,我運行我的遷移,那麼創建的表使用utf8mb4_unicode_ci。他們不應該默認爲utf8嗎?如果是的話,我該如何改變?編譯修補程序和Laravel

第二個問題是當我嘗試在我的本地語言(巴西葡萄牙語)上插入單詞時,使用修補程序,即時通訊獲取由這些字符引起的錯誤。就像這樣:

Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA1tulo ...' for column 'title' at row 1 (SQL: insert into `posts` (`title`, `body`, `updated_at`, `created_at`) values (Título 1, Corpo do primeiro post, 2017-10-09 14:58:40, 2017-10-09 14:58:40))' 

我必須讓補鍋匠接受我的本地語言或做我必須對項目進行任何改變enconding?

遷移代碼:

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreatePostsTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('posts', function (Blueprint $table) { 
      // $table->charset = 'utf8'; 
      // $table->collation = 'utf8_general_ci'; 
      $table->increments('id'); 
      $table->string('title'); 
      $table->mediumText('body'); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::dropIfExists('posts'); 
    } 
} 

在鼓搗我這樣做:

$post = new App\post(); 
$post->title = 'Título 1'; 
$post->body = 'Corpo do primeiro post'; 
$post->save(); 

這是第一次,我使用Laravel,所以我還挺丟失。

+0

可以請您顯示爲您的代碼,以便我們可以幫助 –

+0

嗨,我用我的Post遷移代碼和我在Tinker上做的事情編輯問題。 – churros

回答

0

嘗試添加這些行到你的'config/database.php'文件,然後再試一次。

'charset' => 'utf8', 
'collation' => 'utf8_unicode_ci' 
+0

這解決了我的表格的整理。現在,只有遷移表仍在使用utf8mb4_unicode_ci enconding。修補補給問題仍在繼續。 – churros