Skip to content

Azure SQL: (fields.E180) SQL Server does not support JSONFields #197

@rafaelrodrigues3092

Description

@rafaelrodrigues3092

Software versions

  • Django: 3.2.15
  • mssql-django: 1.1.3
  • python: 3.9.7
  • SQL Server: Azure SQL Server Managed Instance
  • OS: N/A

Table schema and Model

class MyModel(models.Model):
    requestLogId = models.AutoField(db_column="RequestLogId", primary_key=True)
    parameters = models.JSONField(
        db_column="Parameters",
        blank=True,
        null=True,
    )

Database Connection Settings

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": env.str("SQL_DB_NAME"),
        "USER": env.str("SQL_DB_USER"),
        "PASSWORD": env.str("SQL_DB_PASSWORD"),
        "HOST": env.str("SQL_DB_HOST"),
        "PORT": env.str("SQL_DB_PORT"),
        "OPTIONS": {"driver": "ODBC Driver 17 for SQL Server"},
    },
}

Problem description and steps to reproduce

During a migration for a model with a JSONField field, I am seeing the error "MyModel: (fields.E189) SQL Server does not support JSONFields."
I looked through the code it seems to me it may be related to the way SQL Server version is being checked and the fact I am using Azure's SQL Server Managed Instance.

The lib is running

SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar)
SELECT CAST(SERVERPROPERTY('EngineEdition') AS integer)

to check the SQL Server version and engine edition. For engine edition it's checking it against EDITION_AZURE_SQL_DB which is set to 5.

On my Azure Managed Instance, we get:

SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar) as ProductVersion = 12.0.2000.8
SELECT CAST(SERVERPROPERTY('EngineEdition') AS integer) as EngineEdition = 8

Per Microsoft's documentation: https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16

EngineEdition	Database Engine edition of the instance of SQL Server installed on the server.
1 = Personal or Desktop Engine (Not available in SQL Server 2005 (9.x) and later versions.)
2 = Standard (For Standard, Web, and Business Intelligence.)
3 = Enterprise (For Evaluation, Developer, and Enterprise editions.)
4 = Express (For Express, Express with Tools, and Express with Advanced Services)
5 = SQL Database
6 = Microsoft Azure Synapse Analytics
8 = Azure SQL Managed Instance
9 = Azure SQL Edge (For all editions of Azure SQL Edge)
11 = Azure Synapse serverless SQL pool

Expected behavior and actual behavior

Expect JSONField to not throw validation check errors on Azure's Managed Instance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions