diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 4a006bc85d4..1e3db7e7766 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1652,7 +1652,7 @@ class EmailField(CharField): def __init__(self, *args, **kwargs): # max_length=254 to be compliant with RFCs 3696 and 5321 - kwargs['max_length'] = kwargs.get('max_length', 254) + kwargs.setdefault('max_length', 254) super().__init__(*args, **kwargs) def deconstruct(self): @@ -1678,7 +1678,7 @@ class FilePathField(Field): recursive=False, allow_files=True, allow_folders=False, **kwargs): self.path, self.match, self.recursive = path, match, recursive self.allow_files, self.allow_folders = allow_files, allow_folders - kwargs['max_length'] = kwargs.get('max_length', 100) + kwargs.setdefault('max_length', 100) super().__init__(verbose_name, name, **kwargs) def check(self, **kwargs): @@ -2258,7 +2258,7 @@ class URLField(CharField): description = _("URL") def __init__(self, verbose_name=None, name=None, **kwargs): - kwargs['max_length'] = kwargs.get('max_length', 200) + kwargs.setdefault('max_length', 200) super().__init__(verbose_name, name, **kwargs) def deconstruct(self): diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index d14da97cced..00dcbc033cc 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -226,7 +226,7 @@ class FileField(Field): self.storage = storage or default_storage self.upload_to = upload_to - kwargs['max_length'] = kwargs.get('max_length', 100) + kwargs.setdefault('max_length', 100) super().__init__(verbose_name, name, **kwargs) def check(self, **kwargs): diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index db0558b5edd..cfb5ea1ef60 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -808,8 +808,7 @@ class ForeignKey(ForeignObject): parent_link=parent_link, on_delete=on_delete, ) - - kwargs['db_index'] = kwargs.get('db_index', True) + kwargs.setdefault('db_index', True) super().__init__(to, on_delete, from_fields=['self'], to_fields=[to_field], **kwargs)