Closed NZSmartie closed 3 years ago
Thanks for your suggestion, the support will likely come in the future.
Hi, max_length for BinaryField is supported with this commit (https://github.com/microsoft/mssql-django/commit/848c847cec23f18501010d97889b2cbcb7631fbf)
For TextField and JSONField, there are intended to store a large amount of text, so max_length will not be supported.
Microsoft SQL server has a set of maximum capacity specifications as documented Maximum capacity specifications for SQL Server
The
DatabaseWrapper.data_types
dictionary contains amax
parameter for some fields in the database that may or may not have amax_length
size set in the applications model: https://github.com/microsoft/mssql-django/blob/ff5984800c45bc5c9bd95e783425bf77963948e5/mssql/base.py#L74-L102Specifically,
BinaryField
,JSONField
,TextField
have a correspondingmax
size set instead of respecting themax_length
property that can be set in an application's model.For example:
A developer should expect the
access_code
field to be created in the database with the typevarbinary(15)
(orbinary(15)
, but that may be out of scope of this issue). However, since the field's type will end up withvarbinary(max)
, theunique=True
constraint will throw an exception from SQL server as the field is too large to be indexed.This is due to the maximum bytes allowed for an indexable field