Category “Default Category/abc/def/” has not been created. URL key for specified store already exists in Magento2

A new day, a new problem. While importing new products in Magento 2.1.2 via System > Data Transfer > Import something was causing the following error message.

The CSV file was 100% correct, which was making it difficult to figure out why it is causing the error. I ran few more test imports and noticed that the main category actually had an empty space at the end, which I believe was causing the whole problem.

Magento2 Category Name Empty Space

The import ran through without any errors after removing the empty space. However, before I also removed all related URL rewrites as follows. Not sure if this was actually necessary.

After that I rebuilt the re-write table with https://github.com/olegkoval/magento2-regenerate_url_rewrites because for some reason the importer didn’t create the rewrite URLs.

After that everything was working as expected.