Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改数据库列的排序规则在laravel迁移中不起作用_Php_Mysql_Laravel_Laravel 5 - Fatal编程技术网

Php 更改数据库列的排序规则在laravel迁移中不起作用

Php 更改数据库列的排序规则在laravel迁移中不起作用,php,mysql,laravel,laravel-5,Php,Mysql,Laravel,Laravel 5,我想更改“users”表中“about\u me”列的排序规则。为此,我使用下面的代码。我只是将排序规则更改为utf8mb4\u unicode\u ci,但代码不起作用 public function up() { if (Schema::hasColumn("users", "about_me")) { Schema::table("users", function(Blueprint $table) { $t

我想更改“
users
”表中“
about\u me
”列的排序规则。为此,我使用下面的代码。我只是将排序规则更改为
utf8mb4\u unicode\u ci
,但代码不起作用

 public function up()
    {
        if (Schema::hasColumn("users", "about_me")) {
            Schema::table("users", function(Blueprint $table) {
                $table->collation = 'utf8mb4_unicode_ci';
                $table->charset = 'utf8mb4';
            });
        }
 }

我已经在/config/database.php中进行了更改,这有助于我将数据保存在db中,但在获取数据库后,我发现没有显示特殊符号,当我将该列的排序规则更改为utf8mb4_unicode_ci时,它工作得很好。但我想在迁移中做到这一点。当前代码不起作用,我需要正确的代码,该代码运行良好。

Laravel支持修改MySQL的每列排序规则。对于表范围的修改,您需要编写一个原始查询

public function up()
{

    DB::statement("ALTER TABLE users CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
}

在现代Laravel中,有可以在表或列上设置的字符集和排序规则


Laravel支持MySQL按列修改排序规则。您需要在此处编写原始查询来执行表范围的修改。错误:无法访问受保护的属性$table。但它在{$table->table}=>用户中运行良好。另外,Schema::table在这里是无用的,您可以直接编写DB::语句(…),感谢review@ManicDepression。答案已更新。
    // You can change table.
    Schema::table('users`', function (Blueprint $table) {
        $table->charset = 'utf8mb4';
        $table->collation = 'utf8mb4_unicode_ci';
    });

    // You can change on a field of a table.
    Schema::table('users', function (Blueprint $table) {
        $table->string('about_me')->charset('utf8mb4')->collation('utf8mb4_unicode_ci')->change();
    });