laravel/framework

->json() still creates nvarchar(max) columns on SQL Server 2025 despite native JSON datatype support

Ouverte

#57 965 ouverte le 28 nov. 2025

 (5 commentaires) (0 réaction) (0 personne assignée)PHP (11 939 forks)batch import
help wanted

Métriques du dépôt

Stars
 (34 846 étoiles)
Métriques de merge PR
 (Merge moyen 1j 22h) (129 PRs mergées en 30 j)

Description

Laravel Version

12.40.2

PHP Version

8.3.25

Database Driver & Version

Microsoft SQL Server 2025 for MacOS Tahoe (26.1) (using Orbstack's Rosetta and Docker platform settings to emulate Intel)

Description

There is a problem with Laravel's Schema Builder when creating JSON columns on SQL Server 2025. Although SQL Server 2025 introduces native JSON datatype support, the ->json() method still creates nvarchar(max) columns instead of using the new native JSON datatype. This results in underutilization of important database features and may negatively impact performance and validation.

Moreover, there is no mechanism to detect the SQL Server version and conditionally use the native JSON datatype only when supported. For older SQL Server versions, the current fallback to nvarchar(max) should of course remain for backwards compatibility.

Steps To Reproduce

  1. Create a Laravel migration script defining a JSON column:

Schema::create('example_table', function (Blueprint $table) {
    $table->json('data');
});
  1. Run this migration on a SQL Server 2025 database.
  2. Check the datatype of the created column in the database.
  3. You'll see it's a nvarchar datatype instead of json

Guide contributeur