We know that G‑d is the most perfect Being, and that everything exists solely because of Him. Furthermore, He knows everything through His knowledge of Himself, so of course He does not make mistakes.

At the same time, our rabbis shake it up and tell us that there are things which G‑d “regrets” having created, such as the evil inclination.

One way to reconcile these viewpoints is to understand that of course G‑d knew what He was doing when He created these negative things, but He knew that they were necessary in order for humanity to attain the greater good He had in mind. So, while He created these things, He does not “like” them, and we are supposed to view them as temporary.

See Can G‑d Create a Rock That's Too Heavy for Him to Lift? from our selection on G‑d.