diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py index 7c687987db1..b7ca1d3dc4a 100644 --- a/django/contrib/postgres/indexes.py +++ b/django/contrib/postgres/indexes.py @@ -11,11 +11,11 @@ class BrinIndex(Index): # applicable. max_name_length = 31 - def __init__(self, fields=[], name=None, pages_per_range=None): + def __init__(self, *, pages_per_range=None, **kwargs): if pages_per_range is not None and pages_per_range <= 0: raise ValueError('pages_per_range must be None or a positive integer') self.pages_per_range = pages_per_range - super().__init__(fields, name) + super().__init__(**kwargs) def deconstruct(self): path, args, kwargs = super().deconstruct() @@ -33,10 +33,10 @@ class BrinIndex(Index): class GinIndex(Index): suffix = 'gin' - def __init__(self, fields=[], name=None, fastupdate=None, gin_pending_list_limit=None): + def __init__(self, *, fastupdate=None, gin_pending_list_limit=None, **kwargs): self.fastupdate = fastupdate self.gin_pending_list_limit = gin_pending_list_limit - super().__init__(fields, name) + super().__init__(**kwargs) def deconstruct(self): path, args, kwargs = super().deconstruct() diff --git a/django/db/models/indexes.py b/django/db/models/indexes.py index 7e5b8bca30c..4c1aeccfab0 100644 --- a/django/db/models/indexes.py +++ b/django/db/models/indexes.py @@ -11,7 +11,7 @@ class Index: # cross-database compatibility with Oracle) max_name_length = 30 - def __init__(self, fields=[], name=None): + def __init__(self, *, fields=[], name=None): if not isinstance(fields, list): raise ValueError('Index.fields must be a list.') if not fields: diff --git a/docs/ref/contrib/postgres/indexes.txt b/docs/ref/contrib/postgres/indexes.txt index e364f8d83e3..d055a381c5c 100644 --- a/docs/ref/contrib/postgres/indexes.txt +++ b/docs/ref/contrib/postgres/indexes.txt @@ -12,7 +12,7 @@ available from the ``django.contrib.postgres.indexes`` module. ``BrinIndex`` ============= -.. class:: BrinIndex(fields=[], name=None, pages_per_range=None) +.. class:: BrinIndex(pages_per_range=None, **options) Creates a `BRIN index `_. @@ -22,7 +22,7 @@ available from the ``django.contrib.postgres.indexes`` module. ``GinIndex`` ============ -.. class:: GinIndex(fields=[], name=None, fastupdate=None, gin_pending_list_limit=None) +.. class:: GinIndex(fastupdate=None, gin_pending_list_limit=None, **options) Creates a `gin index `_. diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index cd1970f08fe..0b51736768c 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -404,6 +404,17 @@ For custom management commands that use options not created using class MyCommand(BaseCommand): stealth_options = ('option_name', ...) +Indexes no longer accept positional arguments +--------------------------------------------- + +For example:: + + models.Index(['headline', '-pub_date'], 'index_name') + +raises an exception and should be replaced with:: + + models.Index(fields=['headline', '-pub_date'], name='index_name') + Miscellaneous -------------