diff options
Diffstat (limited to 'django/db/models/constraints.py')
-rw-r--r-- | django/db/models/constraints.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/django/db/models/constraints.py b/django/db/models/constraints.py index 2bad8db221..698b278fe8 100644 --- a/django/db/models/constraints.py +++ b/django/db/models/constraints.py @@ -10,16 +10,22 @@ class BaseConstraint: def constraint_sql(self, model, schema_editor): raise NotImplementedError('This method must be implemented by a subclass.') + def full_constraint_sql(self, model, schema_editor): + return schema_editor.sql_constraint % { + 'name': schema_editor.quote_name(self.name), + 'constraint': self.constraint_sql(model, schema_editor), + } + def create_sql(self, model, schema_editor): - sql = self.constraint_sql(model, schema_editor) - return schema_editor.sql_create_check % { + sql = self.full_constraint_sql(model, schema_editor) + return schema_editor.sql_create_constraint % { 'table': schema_editor.quote_name(model._meta.db_table), - 'check': sql, + 'constraint': sql, } def remove_sql(self, model, schema_editor): quote_name = schema_editor.quote_name - return schema_editor.sql_delete_check % { + return schema_editor.sql_delete_constraint % { 'table': quote_name(model._meta.db_table), 'name': quote_name(self.name), } @@ -46,10 +52,7 @@ class CheckConstraint(BaseConstraint): compiler = connection.ops.compiler('SQLCompiler')(query, connection, 'default') sql, params = where.as_sql(compiler, connection) params = tuple(schema_editor.quote_value(p) for p in params) - return schema_editor.sql_check % { - 'name': schema_editor.quote_name(self.name), - 'check': sql % params, - } + return schema_editor.sql_check_constraint % {'check': sql % params} def __repr__(self): return "<%s: check='%s' name=%r>" % (self.__class__.__name__, self.check, self.name) |