#VMware #Cloud #Director #Unregister #vCenter #fails #ERROR #update #delete #table #virtual_center #violates #foreign #key #constraint #fk_vm_virtualcenter #table

Standard disclaimer to start this one off: deleting anything from DB is not supported. Do this at your own risk!!

Have you or someone you know experienced foreign key constraints in VMware Cloud Director aka VCD? If so, please read on…. but be warned, this post contains graphic database content and is not for the squeamish:

Have you seen errors like

  • [ 8ab9ac99-5896-4c3a-81be-d5c1a8ba021b ] org.hibernate.exception.ConstraintViolationException: could not delete: [com.vmware.vcloud.common.model.VirtualCenterModel#037c42a9-5555-4444-1111-8db555b6e2b0]
  • OR: could not delete: [com.vmware.vcloud.common.model.VirtualCenterModel#037c42a9-5555-4444-1111-8db555b6e2b0]
  • ERROR: update or delete on table “virtual_center” violates foreign key constraint “fk_vm_virtualcenter” on table “vm”
    Detail: Key (id)=(037c42a9-5555-4444-1111-8db555b6e2b0) is still referenced from table “vm”.

This means there are still vm objects in the database that most likely have been deleted. Do not worry, this can be fixed. To be safe, making sure that 100% of VMs have already been removed from this vCenter in question but still the original error

Be safe, take a backup before diving in

Click on the vCenter in the VCD UI and grab the ID from the URL or simply grab it from the error message. In the DB, do a select to make sure that you only have 1 record in this virtual_center table.

bblab-db01=# select * from virtual_center where id='037c42a9-5555-4444-1111-8db555b6e2b0';
                  id                  |    name     | description |                  url                  |          username           |
                 password                                         | is_enabled |                 uuid                 | vc_version  | vc_update_level | vsphere_w
eb_client_url | is_use_vsphere_service | mark_for_delete | status | version | workload_folder_name | workload_folder_moref | compute_provider_scope | listener_co
nfig | tenant_scoped | provider_scoped | vc_none_network_name | vc_none_network_moref | comp_version_id | proxy_id | vc_build_number | certificate_id
 037c42a9-b59b-43de-9514-8db555b6e2b0 | bblab-vc02 |             | https://bblab-vc02/sdk | administrator@vsphere.local | Wlongstringofdataherethatdoesnotneedtobeinthisposthere== | f          | asdfasdf-190c-4055-8985-asdf65165asdf| TBD | 0               |
              | f                      | f               | READY  |      11 |                      |                       |                        |
   0 | f             | t               |                      |                       |         |          | 20178686        |
(1 row)


Making sure there is only a single vCenter that we are running against. Do a select to find the vms in this vCenter. It would be recommended that you remove them 1 by 1 as you see the id within the painful error above, however; you could be darning and delete all vms …you’ve come this far…

bblab-db01=#SELECT * from vm where vc_id='037c42a9-5555-4444-1111-8db555b6e2b0';
(38 rows)
bblab-db01=# DELETE from vm where vc_id='037c42a9-5555-4444-1111-8db555b6e2b0';

After I recklessly deleted all vms from that table where the vC ID matched, I was able to delete the vCenter from the VCD UI without issue.

Please feel free to reach out, hope this helps



ahmedaljanahy Creative Designer @al.janahy Founder of @inkhost I hope to stay passionate in what I doing

Leave a Reply

Your email address will not be published. Required fields are marked *