diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 0184fa1cbe..20378fc2c1 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -259,7 +259,10 @@ WHEN (new.%(col_name)s IS NULL) # string instead of null, but only if the field accepts the # empty string. if value is None and field and field.empty_strings_allowed: - value = '' + if field.get_internal_type() == 'BinaryField': + value = bytes() # same as '' on PY2 but different on PY3 + else: + value = '' # Convert 1 or 0 to True or False elif value in (1, 0) and field and field.get_internal_type() in ('BooleanField', 'NullBooleanField'): value = bool(value) diff --git a/django/db/backends/oracle/schema.py b/django/db/backends/oracle/schema.py index 7843b96943..986cd95e75 100644 --- a/django/db/backends/oracle/schema.py +++ b/django/db/backends/oracle/schema.py @@ -3,6 +3,7 @@ import datetime import binascii from django.utils import six +from django.utils.text import force_text from django.db.backends.schema import BaseDatabaseSchemaEditor from django.db.utils import DatabaseError @@ -23,8 +24,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): return "'%s'" % value elif isinstance(value, six.string_types): return "'%s'" % six.text_type(value).replace("\'", "\'\'") - elif isinstance(value, buffer): - return "'%s'" % binascii.hexlify(value) + elif (isinstance(value, six.memoryview) or + six.PY3 and isinstance(value, bytes)): + return "'%s'" % force_text(binascii.hexlify(value)) elif isinstance(value, bool): return "1" if value else "0" else: