Skip to content

Commit 79e421a

Browse files
authored
Fix inspectdb (#96)
1 parent 33389b6 commit 79e421a

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

sql_server/pyodbc/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
8989
'OneToOneField': 'int',
9090
'PositiveIntegerField': 'int',
9191
'PositiveSmallIntegerField': 'smallint',
92+
'PositiveBigIntegerField': 'bigint',
9293
'SlugField': 'nvarchar(%(max_length)s)',
9394
'SmallAutoField': 'smallint IDENTITY (1, 1)',
9495
'SmallIntegerField': 'smallint',

sql_server/pyodbc/features.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
class DatabaseFeatures(BaseDatabaseFeatures):
6+
can_introspect_json_field = False
7+
has_native_json_field = False
68
has_native_uuid_field = False
79
allow_sliced_subqueries_with_in = False
810
can_introspect_autofield = True
@@ -57,3 +59,11 @@ def supports_partial_indexes(self):
5759
@cached_property
5860
def supports_functions_in_partial_indexes(self):
5961
return self.connection.sql_server_version > 2005
62+
63+
@cached_property
64+
def introspected_field_types(self):
65+
return {
66+
**super().introspected_field_types,
67+
'GenericIPAddressField': 'CharField',
68+
'PositiveBigIntegerField': 'BigIntegerField'
69+
}

sql_server/pyodbc/introspection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import pyodbc as Database
2+
from collections import namedtuple
23

34
from django.db.backends.base.introspection import (
4-
BaseDatabaseIntrospection, FieldInfo, TableInfo,
5+
BaseDatabaseIntrospection, TableInfo,
56
)
67
from django.db.models.indexes import Index
78

89
SQL_AUTOFIELD = -777555
910
SQL_BIGAUTOFIELD = -777444
1011

12+
FieldInfo = namedtuple('FieldInfo', 'name type_code display_size internal_size precision scale null_ok default')
13+
1114

1215
class DatabaseIntrospection(BaseDatabaseIntrospection):
1316
# Map type codes to Django Field types.

testapp/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@
113113
'indexes.tests.PartialIndexTests.test_multiple_conditions',
114114
'indexes.tests.SchemaIndexesNotPostgreSQLTests.test_create_index_ignores_opclasses',
115115
'inspectdb.tests.InspectDBTestCase.test_introspection_errors',
116-
'inspectdb.tests.InspectDBTestCase.test_json_field',
117-
'inspectdb.tests.InspectDBTestCase.test_number_field_types',
118116
'introspection.tests.IntrospectionTests.test_get_constraints',
119117
'introspection.tests.IntrospectionTests.test_get_table_description_types',
120118
'introspection.tests.IntrospectionTests.test_smallautofield',

0 commit comments

Comments
 (0)