Skip to content

Magento create customer and force customer id

I have magento 2.4.3.

I need to do a customer migration and I should force the entity_id but I get this error

No such entity with customerId = 40

I tried this code:

$customer = $this->_objectManager->get('MagentoCustomerApiDataCustomerInterfaceFactory')->create();
                    $customer->setWebsiteId($websiteId);
                    $customer->setEmail($email);
                    $customer->setFirstname($cliente['nome']);
                    $customer->setLastname($cliente['cognome']);
                    $customer->setId(40);
                    $hashing = (string)rand(0,1000000000)."mnhyty47hbs";
                    $hashedPassword = $this->_objectManager->get('MagentoFrameworkEncryptionEncryptorInterface')->getHash($hashing, true); 
                   
                    $this->_objectManager->get('MagentoCustomerApiCustomerRepositoryInterface')->save($customer, $hashedPassword);

How can i do that?