Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
b22917bd
Kaydet (Commit)
b22917bd
authored
Haz 17, 2014
tarafından
Andrew Godwin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22851: BinaryView wasn't getting a binary default
üst
82c935d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
schema.py
django/db/backends/schema.py
+6
-3
tests.py
tests/schema/tests.py
+21
-1
No files found.
django/db/backends/schema.py
Dosyayı görüntüle @
b22917bd
...
@@ -8,7 +8,7 @@ from django.db.transaction import atomic
...
@@ -8,7 +8,7 @@ from django.db.transaction import atomic
from
django.utils.encoding
import
force_bytes
from
django.utils.encoding
import
force_bytes
from
django.utils.log
import
getLogger
from
django.utils.log
import
getLogger
from
django.utils.six.moves
import
reduce
from
django.utils.six.moves
import
reduce
from
django.utils
.six
import
callable
from
django.utils
import
six
logger
=
getLogger
(
'django.db.backends.schema'
)
logger
=
getLogger
(
'django.db.backends.schema'
)
...
@@ -169,11 +169,14 @@ class BaseDatabaseSchemaEditor(object):
...
@@ -169,11 +169,14 @@ class BaseDatabaseSchemaEditor(object):
if
field
.
has_default
():
if
field
.
has_default
():
default
=
field
.
get_default
()
default
=
field
.
get_default
()
elif
not
field
.
null
and
field
.
blank
and
field
.
empty_strings_allowed
:
elif
not
field
.
null
and
field
.
blank
and
field
.
empty_strings_allowed
:
default
=
""
if
field
.
get_internal_type
()
==
"BinaryField"
:
default
=
six
.
binary_type
()
else
:
default
=
six
.
text_type
()
else
:
else
:
default
=
None
default
=
None
# If it's a callable, call it
# If it's a callable, call it
if
callable
(
default
):
if
six
.
callable
(
default
):
default
=
default
()
default
=
default
()
# Run it through the field's get_db_prep_save method so we can send it
# Run it through the field's get_db_prep_save method so we can send it
# to the database.
# to the database.
...
...
tests/schema/tests.py
Dosyayı görüntüle @
b22917bd
...
@@ -4,9 +4,10 @@ import unittest
...
@@ -4,9 +4,10 @@ import unittest
from
django.test
import
TransactionTestCase
from
django.test
import
TransactionTestCase
from
django.db
import
connection
,
DatabaseError
,
IntegrityError
,
OperationalError
from
django.db
import
connection
,
DatabaseError
,
IntegrityError
,
OperationalError
from
django.db.models.fields
import
IntegerField
,
TextField
,
CharField
,
SlugField
,
BooleanField
from
django.db.models.fields
import
IntegerField
,
TextField
,
CharField
,
SlugField
,
BooleanField
,
BinaryField
from
django.db.models.fields.related
import
ManyToManyField
,
ForeignKey
from
django.db.models.fields.related
import
ManyToManyField
,
ForeignKey
from
django.db.transaction
import
atomic
from
django.db.transaction
import
atomic
from
django.utils
import
six
from
.models
import
(
Author
,
AuthorWithM2M
,
Book
,
BookWithLongName
,
from
.models
import
(
Author
,
AuthorWithM2M
,
Book
,
BookWithLongName
,
BookWithSlug
,
BookWithM2M
,
Tag
,
TagIndexed
,
TagM2MTest
,
TagUniqueRename
,
BookWithSlug
,
BookWithM2M
,
Tag
,
TagIndexed
,
TagM2MTest
,
TagUniqueRename
,
UniqueTest
,
Thing
,
TagThrough
,
BookWithM2MThrough
,
AuthorTag
,
AuthorWithM2MThrough
)
UniqueTest
,
Thing
,
TagThrough
,
BookWithM2MThrough
,
AuthorTag
,
AuthorWithM2MThrough
)
...
@@ -269,6 +270,25 @@ class SchemaTests(TransactionTestCase):
...
@@ -269,6 +270,25 @@ class SchemaTests(TransactionTestCase):
# Make sure the values were transformed correctly
# Make sure the values were transformed correctly
self
.
assertEqual
(
Author
.
objects
.
extra
(
where
=
[
"thing = 1"
])
.
count
(),
2
)
self
.
assertEqual
(
Author
.
objects
.
extra
(
where
=
[
"thing = 1"
])
.
count
(),
2
)
def
test_add_field_binary
(
self
):
"""
Tests binary fields get a sane default (#22851)
"""
# Create the table
with
connection
.
schema_editor
()
as
editor
:
editor
.
create_model
(
Author
)
# Add the new field
new_field
=
BinaryField
(
blank
=
True
)
new_field
.
set_attributes_from_name
(
"bits"
)
with
connection
.
schema_editor
()
as
editor
:
editor
.
add_field
(
Author
,
new_field
,
)
# Ensure the field is right afterwards
columns
=
self
.
column_classes
(
Author
)
self
.
assertEqual
(
columns
[
'bits'
][
0
],
"BinaryField"
)
def
test_alter
(
self
):
def
test_alter
(
self
):
"""
"""
Tests simple altering of fields
Tests simple altering of fields
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment