Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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
Laravel迁移:托管服务器上的Json列出错,但本地Xampp服务器上没有_Laravel_Eloquent_Laravel 8_Laravel Migrations - Fatal编程技术网

Laravel迁移:托管服务器上的Json列出错,但本地Xampp服务器上没有

Laravel迁移:托管服务器上的Json列出错,但本地Xampp服务器上没有,laravel,eloquent,laravel-8,laravel-migrations,Laravel,Eloquent,Laravel 8,Laravel Migrations,我最近为下载并安装了一个包,其中发布了迁移&这些迁移在某些表中有JSON列 迁移: public function up(): void { Schema::create($this->table(), function (Blueprint $table) { $table->bigIncrements('id'); $table->morphs('payable'); $table->enum('type', [

我最近为下载并安装了一个包,其中发布了迁移&这些迁移在某些表中有
JSON

迁移:

public function up(): void
{
    Schema::create($this->table(), function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->morphs('payable');
        $table->enum('type', ['deposit', 'withdraw'])->index();
        $table->decimal('amount', 64, 0);
        $table->boolean('confirmed');
        $this->json($table, 'meta')->nullable();
        $table->uuid('uuid')->unique();
        $table->timestamps();

        $table->index(['payable_type', 'payable_id', 'type'], 'payable_type_ind');
        $table->index(['payable_type', 'payable_id', 'confirmed'], 'payable_confirmed_ind');
        $table->index(['payable_type', 'payable_id', 'type', 'confirmed'], 'payable_type_confirmed_ind');
    });
}

public function json(Blueprint $table, string $column): ColumnDefinition
{
    $conn = DB::connection();
    if ($conn instanceof MySqlConnection || $conn instanceof PostgresConnection) {
        $pdo = $conn->getPdo();
        try {
            $sql = 'SELECT JSON_EXTRACT(\'[10, 20, [30, 40]]\', \'$[1]\');';
            $prepare = $pdo->prepare($sql);
            $prepare->fetch();
        } catch (\Throwable $throwable) {
            return $table->text($column);
        }
    }

    return $table->json($column);
}

protected function table(): string
{
    return (new Transaction())->getTable();
}

public function down(): void
{
    Schema::drop($this->table());
}
这种迁移在本地xampp服务器上运行良好,但我不明白为什么我的live服务器出现错误。下面是我在尝试运行迁移时遇到的错误

我尝试使用
$table->json('meta')->nullable()
这也不起作用,尽管我认为这不是一件合适的事情,因为就我所见,
$this->json()
调用
json
函数


有些人还建议使用文本而不是Json,但我觉得这不是一个解决方案。我们如何解决这个问题?

请检查您的MySQL版本,如果它是5.6或更低版本,json函数将不起作用。
您应该使用MySQL版本5.7或更高版本来使用json函数。或者在MySQL版本5.6或更低版本中使用“text”作为列。

您是否检查了您安装的MySQL服务器版本是否支持JSON数据类型?@matticustard哦,是的,我认为这就是问题所在。我刚刚检查过它不支持Json数据类型。谢谢,你说得对。我想这就是问题所在。我当前的SQL版本不支持JSON数据类型。非常感谢,很有帮助。请你把它投上去,这样也可以帮助别人。