Skip to content

Fix inspectdb #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sql_server/pyodbc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
'OneToOneField': 'int',
'PositiveIntegerField': 'int',
'PositiveSmallIntegerField': 'smallint',
'PositiveBigIntegerField': 'bigint',
'SlugField': 'nvarchar(%(max_length)s)',
'SmallAutoField': 'smallint IDENTITY (1, 1)',
'SmallIntegerField': 'smallint',
Expand Down
10 changes: 10 additions & 0 deletions sql_server/pyodbc/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class DatabaseFeatures(BaseDatabaseFeatures):
can_introspect_json_field = False
has_native_json_field = False
has_native_uuid_field = False
allow_sliced_subqueries_with_in = False
can_introspect_autofield = True
Expand Down Expand Up @@ -57,3 +59,11 @@ def supports_partial_indexes(self):
@cached_property
def supports_functions_in_partial_indexes(self):
return self.connection.sql_server_version > 2005

@cached_property
def introspected_field_types(self):
return {
**super().introspected_field_types,
'GenericIPAddressField': 'CharField',
'PositiveBigIntegerField': 'BigIntegerField'
}
5 changes: 4 additions & 1 deletion sql_server/pyodbc/introspection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import pyodbc as Database
from collections import namedtuple

from django.db.backends.base.introspection import (
BaseDatabaseIntrospection, FieldInfo, TableInfo,
BaseDatabaseIntrospection, TableInfo,
)
from django.db.models.indexes import Index

SQL_AUTOFIELD = -777555
SQL_BIGAUTOFIELD = -777444

FieldInfo = namedtuple('FieldInfo', 'name type_code display_size internal_size precision scale null_ok default')


class DatabaseIntrospection(BaseDatabaseIntrospection):
# Map type codes to Django Field types.
Expand Down
2 changes: 0 additions & 2 deletions testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@
'indexes.tests.PartialIndexTests.test_multiple_conditions',
'indexes.tests.SchemaIndexesNotPostgreSQLTests.test_create_index_ignores_opclasses',
'inspectdb.tests.InspectDBTestCase.test_introspection_errors',
'inspectdb.tests.InspectDBTestCase.test_json_field',
'inspectdb.tests.InspectDBTestCase.test_number_field_types',
'introspection.tests.IntrospectionTests.test_get_constraints',
'introspection.tests.IntrospectionTests.test_get_table_description_types',
'introspection.tests.IntrospectionTests.test_smallautofield',
Expand Down