Name has already been taken

Problem:

I am using Foreman 2.1.0 with Puppetserver 6.16. After I run “puppet agent -t” on my agent machine, it shows up in Foreman console. Good. But then when I try to add this host to any host group or change anything, either from Foreman console or with hammer command, I got error: “Name has already been taken”. This happened to 7 out of my 300 hosts.

Expected outcome:
Host can be added to a host group.

Foreman and Proxy versions:
Foreman 2.1.0

Foreman and Proxy plugin versions:

Distribution and version:

Other relevant data:
/var/log/foreman/production.log:

2020-07-06T14:49:31 [I|app|67c71775] Parameters: {“utf8”=>“✓”, “authenticity_token”=>xxxxxxxx==", “host”=>{“name”=>“myhost01.example.com”, “hostgroup_id”=>“3”, “environment_id”=>“1”, “puppet_proxy_id”=>“1”, “puppet_ca_proxy_id”=>“1”, “puppetclass_ids”=>[""], “managed”=>“false”, “progress_report_id”=>"[FILTERED]", “interfaces_attributes”=>{“0”=>{"_destroy"=>“0”, “mac”=>“xx:xx:xx:xx”, “identifier”=>“eno1”, “name”=>“myhost01”, “domain_id”=>“1”, “ip”=>“xx.xx.xx.xx”, “ip6”=>"", “managed”=>“1”, “primary”=>“1”, “provision”=>“1”, “execution”=>“1”, “tag”=>"", “attached_to”=>"", “id”=>“73”}, “1”=>{"_destroy"=>“0”, “mac”=>“xx:xx:xx:xx”, “identifier”=>“virbr0”, “name”=>"", “domain_id”=>"", “ip”=>“192.168.122.1”, “ip6”=>"", “managed”=>“0”, “primary”=>“0”, “provision”=>“0”, “execution”=>“0”, “attached_devices”=>"", “id”=>“74”}, “2”=>{"_destroy"=>“0”, “mac”=>“52:54:00:95:b1:9e”, “identifier”=>“virbr0-nic”, “name”=>"", “domain_id”=>"", “ip”=>"", “ip6”=>"", “managed”=>“0”, “primary”=>“0”, “provision”=>“0”, “execution”=>“0”, “tag”=>"", “attached_to”=>"", “id”=>“75”}, “3”=>{"_destroy"=>“0”, “mac”=>“xx:xx:xx:xx”, “identifier”=>“wlp1s0”, “name”=>"", “domain_id”=>"", “ip”=>"", “ip6”=>"", “managed”=>“0”, “primary”=>“0”, “provision”=>“0”, “execution”=>“0”, “tag”=>"", “attached_to”=>"", “id”=>“76”}}, “is_owned_by”=>“4-Users”, “enabled”=>“1”, “model_id”=>“13”, “comment”=>"", “overwrite”=>“false”}, “id”=>“22”}
2020-07-06T14:49:31 [W|app|67c71775] Not queueing Host::Managed: [“Name has already been taken”]
2020-07-06T14:49:31 [E|app|67c71775] Failed to save: Name has already been taken

There must already be existing host registered with that name. It can be in a different organization too, even in the “Any Organization” context, make sure you switch to it and delete them.