簡體   English   中英

使用修補匠和Laravel編碼

[英]Encoding with tinker and Laravel

我正在嘗試使用修補程序來操縱項目的表,因此,我遇到的第一個問題是創建了utf8編碼的數據庫,然后運行遷移,然后運行創建的表正在使用utf8mb4_unicode_ci。 它們默認不應該是utf8嗎? 如果是,我該如何更改?

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

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))'

我是否必須讓修補匠接受我的當地語言,還是必須對項目進行相應的更改?

遷移代碼:

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,所以我有點迷路。

嘗試將這些行添加到“ config / database.php”文件中,然后重試。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM