Solved I messed up libevent and now can't update unbound

I noticed this morning that devel/libevent2 was orphaned so I just did pkg delete libevent2 to get rid of it.

I knew it was only required by dns/unbound and assumed when updating unbound, it would automatically solve my problem. Well it didn't ..

I noticed in UPDATING that I should have ran this :
  AFFECTS: devel/libevent2

  libevent2 has been renamed back to libevent as the default version.
  If you manage out of tree ports make sure to run the following:

    # pkg set -n libevent2:libevent
    # pkg set -o devel/libevent2:devel/libevent
However, I use the ports system so those instructions wouldn't have worked for me anyways.

Is there any way I can fix this issue now - when devel/libevent2 is now uninstalled?
However, I use the ports system so those instructions wouldn't have worked for me anyways.
You actually have to run those commands, even if you use ports. Remeber, everything is registered with pkg(8) regardless if you use ports or packages. Ports build packages and it's those packages that eventually get installed.
That I didn't know ... anything I can do to fix this issue now though?
$ sudo pkg set -n libevent2:libevent
Change name from libevent2 to libevent for all dependencies? [y/N]: y
pkg: sqlite error while executing UPDATE deps SET name = ?1, version=(SELECT version FROM packages WHERE name = ?1) WHERE package_id = ?2 AND name = ?3 in file pkgdb.c:2559: NOT NULL constraint failed: deps.version
You can probably skip that one as there's no libevent installed any more. The pkg set -o devel/libevent2:devel/libevent should work though.

But the easiest fix is probably to remove unbound (and make sure there's no libevent/libevent2 either), then rebuild it. It should simply pull in libevent as a dependency.
Unfortunately I get the same error ...
$ sudo pkg set -o devel/libevent2:devel/libevent
Change origin from devel/libevent2 to devel/libevent for all dependencies? [y/N]: y
pkg: sqlite error while executing UPDATE deps SET origin = ?1, name=(SELECT name FROM packages WHERE origin = ?1), version=(SELECT version FROM packages WHERE origin = ?1) WHERE package_id = ?2 AND origin = ?3 in file pkgdb.c:2559: NOT NULL constraint failed:
I just did a quick test and it failed with :
===>   unbound-1.6.0_2 depends on shared library: - not found
===>  License BSD3CLAUSE accepted by the user
===>  Found saved configuration for libevent-2.1.8
===>   libevent-2.1.8 depends on file: /usr/local/sbin/pkg - found
=> libevent-libevent-release-2.1.8-stable_GH0.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch
libevent-libevent-release-2.1.8-stable_GH0.tar100% of  684 kB 2122 kBps 00m00s
===> Fetching all distfiles required by libevent-2.1.8 for building
===>  Extracting for libevent-2.1.8
=> SHA256 Checksum OK for libevent-libevent-release-2.1.8-stable_GH0.tar.gz.
===>  Patching for libevent-2.1.8
===>  Applying FreeBSD patches for libevent-2.1.8
2 out of 3 hunks failed--saving rejects to evdns.c.rej
=> FreeBSD patch patch-evdns.c failed to apply cleanly.
*** Error code 1
Did you run #make config already? Not sure if that could affect this, but it sounds somewhat logical.

For the record: the port builds cleanly on my end, so it has to be something local.
If you're using portsnap, you've probably got the same issue I had.

It looks like portsnap doesn't replace devel/libevent with devel/libevent2 so much as it copies the contents of libevent2 into libevent and deletes libevent2, leaving a bunch of obsolete patch files in place.

Try deleting the following from /usr/ports/devel/libevent/files:
  • patch-evdns.c
  • patch-event.c
  • patch-evutil.c
  • patch-http.c
  • patch-signal.c