2. If $\alpha \in\left(\frac{\pi}{2}, \pi\right)$, then the range of real numbers $x$ that satisfy the equation
$$
\log _{2}\left(x^{2}-x+2\right)=\sin \alpha-\sqrt{3} \cos \alpha
$$

is ( ).
(A) $-1<x<2$
(B) $-1<x<0$ or $1<x<2$
(C) $0 \leqslant x \leqslant 1$
(D) $-1 \leqslant x<0$ or $1<x \leqslant 2$
2.D.

Since $\frac{\pi}{2}<\alpha<\pi$, therefore, $\frac{\pi}{6}<\alpha-\frac{\pi}{3}<\frac{2 \pi}{3}$.
Thus, $\sin \alpha-\sqrt{3} \cos \alpha=2 \sin \left(\alpha-\frac{\pi}{3}\right) \in(1,2]$.
Hence, $1<\log _{2}\left(x^{2}-x+2\right) \leqslant 2$. This gives $2<x^{2}-x+2 \leqslant 4$.

Solving, we get $-1 \leqslant x<0$ or $1<x \leqslant 2$.