最近,我下载并安装了一个发布迁移的包&这些迁移在某些表中有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服务器中运行良好,但我不明白为什么在我的活动服务器中出现错误。下面是我在尝试运行迁移时遇到的错误。

我尝试使用$table->json('meta')->nullable();,这也不起作用,不过我认为这样做并不合适,因为据我所见,$this->json()调用了json函数。
有些人还建议用文本代替Json,但我觉得这不是一个解决方案。我们怎样才能解决这个问题?
发布于 2021-05-25 08:36:38
请检查您的MySQL版本,如果它是5.6或低于函数json将无法工作。您应该使用MySQL版本5.7或更高版本来使用json函数。或者使用"text“作为MySQL版本5.6或更低版本中的列。
https://stackoverflow.com/questions/67684112
复制相似问题