Taking the derivative of x
If we're taking derivatives, that means the things on each side of the equals sign are functions. What you've demonstrated is the correct statement that if $f$ is the identity function $f(x) = x$ and $g$ is the constant function $g(x) = 1$, then $f\ne g$.
Partial derivative requires a function as argument therefore if we assume, with little a abuse of notation, $x$ as a function $x= x(x,y,z,\ldots)$ and we states that $x$ is a constant function $x(x,y,z,\ldots)=1$ then
$$\frac{\partial }{\partial x} x(x,y,z,\ldots) = \frac{\partial }{\partial x}1=0$$
Note that of course it should be better to use a different notation for $x$ as a function to distinguish it form the variable $x$, that is for example $\bar x= \bar x(x,y,z,\ldots)$.
You can take derivative of both sides of an identity not an equation.
For example $$\sin^2 x + \cos^2 x =1$$ is an identity, so we can differentiate to get $$2\sin x \cos x -2\sin x\cos x =0$$ or $$\cos 2x = \cos ^2 x - \sin ^2 x $$ gives $$-2\sin 2x = -2\sin x \cos x-2\sin x \cos x $$
Which is $$\sin 2x = 2\sin x \cos x$$
But you can not differentiate the equation $$\sin x =x$$ to get $$\cos x =1$$