@@ -438,14 +438,13 @@ def _create_collection(self, model):
438438 auto_encryption_opts = getattr (client ._options , "auto_encryption_opts" , None )
439439 if not auto_encryption_opts :
440440 raise ImproperlyConfigured (
441- "Encrypted fields found but "
442- f"DATABASES[{ self .connection .alias } ]['OPTIONS'] is missing "
443- f"Encrypted fields found but DATABASES['{ self .connection .alias } ']['OPTIONS'] is missing auto_encryption_opts."
441+ f"Encrypted fields found but DATABASES['{ self .connection .alias } ']['OPTIONS'] "
442+ "is missing auto_encryption_opts."
444443 )
445444 encrypted_fields_map = getattr (auto_encryption_opts , "_encrypted_fields_map" , None )
446445 if not encrypted_fields_map :
447446 encrypted_fields_map = self ._get_encrypted_fields_map (
448- model , client , auto_encryption_opts
447+ model , client , create_data_keys = True
449448 )
450449 else :
451450 # If the encrypted fields map is provided, get the map for the
@@ -486,7 +485,8 @@ def _get_encrypted_fields_map(self, model, client, create_data_keys=False):
486485 if not key_doc :
487486 raise ValueError (
488487 f"No key found in keyvault for keyAltName={ key_alt_name } . "
489- "You may need to run the management command with '--create-data-keys' to create missing keys."
488+ "You may need to run the management command with "
489+ "'--create-data-keys' to create missing keys."
490490 )
491491 data_key = key_doc ["_id" ]
492492 field_dict = {
0 commit comments