Skip to content

Commit

Permalink
Error on unsupported unique constraint conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjb committed Jan 15, 2021
1 parent 79e421a commit 336995e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sql_server/pyodbc/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
Statement as DjStatement,
Table,
)
from django.db.models import Index
from django.db.models import Index, UniqueConstraint
from django.db.models.fields import AutoField, BigAutoField
from django.db.models.sql.where import AND
from django.db.transaction import TransactionManagementError
from django.utils.encoding import force_str

Expand Down Expand Up @@ -970,3 +971,9 @@ def remove_field(self, model, field):
for sql in list(self.deferred_sql):
if isinstance(sql, Statement) and sql.references_column(model._meta.db_table, field.column):
self.deferred_sql.remove(sql)

def add_constraint(self, model, constraint):
if isinstance(constraint, UniqueConstraint) and constraint.condition and constraint.condition.connector != AND:
raise NotImplementedError("The backend does not support %s conditions on unique constraint %s." %
(constraint.condition.connector, constraint.name))
super().add_constraint(model, constraint)

0 comments on commit 336995e

Please sign in to comment.