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
6421bd70
Kaydet (Commit)
6421bd70
authored
Mar 16, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #29227 -- Made inspectdb generate BooleanField(null=True) rather than NullBooleanField.
üst
5fa4f40f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
13 additions
and
36 deletions
+13
-36
inspectdb.py
django/core/management/commands/inspectdb.py
+2
-5
features.py
django/db/backends/base/features.py
+4
-14
features.py
django/db/backends/mysql/features.py
+1
-3
2.1.txt
docs/releases/2.1.txt
+3
-0
tests.py
tests/inspectdb/tests.py
+2
-10
tests.py
tests/schema/tests.py
+1
-4
No files found.
django/core/management/commands/inspectdb.py
Dosyayı görüntüle @
6421bd70
...
...
@@ -142,11 +142,8 @@ class Command(BaseCommand):
# Add 'null' and 'blank', if the 'null_ok' flag was present in the
# table description.
if
row
[
6
]:
# If it's NULL...
if
field_type
==
'BooleanField('
:
field_type
=
'NullBooleanField('
else
:
extra_params
[
'blank'
]
=
True
extra_params
[
'null'
]
=
True
extra_params
[
'blank'
]
=
True
extra_params
[
'null'
]
=
True
field_desc
=
'
%
s =
%
s
%
s'
%
(
att_name
,
...
...
django/db/backends/base/features.py
Dosyayı görüntüle @
6421bd70
...
...
@@ -141,6 +141,10 @@ class BaseDatabaseFeatures:
# Can the backend introspect a TimeField, instead of a DateTimeField?
can_introspect_time_field
=
True
# Some backends may not be able to differentiate BooleanField from other
# fields such as IntegerField.
introspected_boolean_field_type
=
'BooleanField'
# Can the backend introspect the column order (ASC/DESC) for indexes?
supports_index_column_ordering
=
True
...
...
@@ -268,17 +272,3 @@ class BaseDatabaseFeatures:
except
NotSupportedError
:
return
False
return
True
def
introspected_boolean_field_type
(
self
,
field
=
None
):
"""
What is the type returned when the backend introspects a BooleanField?
The `field` argument may be used to give further details of the field
to be introspected.
The return value from this function is compared by tests against actual
introspection results; it should provide expectations, not run an
introspection itself.
"""
if
field
and
field
.
null
:
return
'NullBooleanField'
return
'BooleanField'
django/db/backends/mysql/features.py
Dosyayı görüntüle @
6421bd70
...
...
@@ -18,6 +18,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
can_introspect_binary_field
=
False
can_introspect_small_integer_field
=
True
can_introspect_positive_integer_field
=
True
introspected_boolean_field_type
=
'IntegerField'
supports_index_column_ordering
=
False
supports_timezones
=
False
requires_explicit_null_ordering_when_grouping
=
True
...
...
@@ -68,9 +69,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
cursor
.
execute
(
"SELECT 1 FROM mysql.time_zone LIMIT 1"
)
return
cursor
.
fetchone
()
is
not
None
def
introspected_boolean_field_type
(
self
,
*
args
,
**
kwargs
):
return
'IntegerField'
@cached_property
def
is_sql_auto_is_null_enabled
(
self
):
with
self
.
connection
.
cursor
()
as
cursor
:
...
...
docs/releases/2.1.txt
Dosyayı görüntüle @
6421bd70
...
...
@@ -285,6 +285,9 @@ Database backend API
* ``DatabaseOperations.distinct_sql()`` now requires an additional ``params``
argument and returns a tuple of SQL and parameters instead of a SQL string.
* ``DatabaseFeatures.introspected_boolean_field_type`` is changed from a method
to a property.
:mod:`django.contrib.gis`
-------------------------
...
...
tests/inspectdb/tests.py
Dosyayı görüntüle @
6421bd70
...
...
@@ -7,8 +7,6 @@ from django.db import connection
from
django.db.backends.base.introspection
import
TableInfo
from
django.test
import
TestCase
,
TransactionTestCase
,
skipUnlessDBFeature
from
.models
import
ColumnTypes
def
inspectdb_tables_only
(
table_name
):
"""
...
...
@@ -96,15 +94,9 @@ class InspectDBTestCase(TestCase):
else
:
assertFieldType
(
'big_int_field'
,
"models.IntegerField()"
)
bool_field
=
ColumnTypes
.
_meta
.
get_field
(
'bool_field'
)
bool_field_type
=
connection
.
features
.
introspected_boolean_field_type
(
bool_field
)
bool_field_type
=
connection
.
features
.
introspected_boolean_field_type
assertFieldType
(
'bool_field'
,
"models.{}()"
.
format
(
bool_field_type
))
null_bool_field
=
ColumnTypes
.
_meta
.
get_field
(
'null_bool_field'
)
null_bool_field_type
=
connection
.
features
.
introspected_boolean_field_type
(
null_bool_field
)
if
'BooleanField'
in
null_bool_field_type
:
assertFieldType
(
'null_bool_field'
,
"models.{}()"
.
format
(
null_bool_field_type
))
else
:
assertFieldType
(
'null_bool_field'
,
"models.{}(blank=True, null=True)"
.
format
(
null_bool_field_type
))
assertFieldType
(
'null_bool_field'
,
'models.{}(blank=True, null=True)'
.
format
(
bool_field_type
))
if
connection
.
features
.
can_introspect_decimal_field
:
assertFieldType
(
'decimal_field'
,
"models.DecimalField(max_digits=6, decimal_places=1)"
)
...
...
tests/schema/tests.py
Dosyayı görüntüle @
6421bd70
...
...
@@ -476,10 +476,7 @@ class SchemaTests(TransactionTestCase):
columns
=
self
.
column_classes
(
Author
)
# BooleanField are stored as TINYINT(1) on MySQL.
field_type
=
columns
[
'awesome'
][
0
]
self
.
assertEqual
(
field_type
,
connection
.
features
.
introspected_boolean_field_type
(
new_field
)
)
self
.
assertEqual
(
field_type
,
connection
.
features
.
introspected_boolean_field_type
)
def
test_add_field_default_transform
(
self
):
"""
...
...
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