Deriving de Broglie's equation (as per my text and teacher) involves equating $E = mc^2$ with $E = h\nu$, where $\nu$ is the frequency. It goes like :
$$mc^2 = h\nu$$ $$mc^2 = \frac{hc}{\lambda}$$ $$mc = \frac{h}{\lambda}.$$
Then we replace $c$ with the velocity of the particle to apply it generally
i.e. $$mv = \frac{h}{\lambda}.$$
My doubt is exactly about this step. As far as I have read before and after learning this equation, I understood that $c$ in $E = mc^2$ was mainly used as a constant which can equate energy and mass rather than something relating energy, mass and velocity of the particle. Thus replacing $c$ with $v$ makes no sense as it would have contradicted the equivalence of $E=mc^2$ in the first place.
Can someone explain how $c$ can be replaced with $v$ without contradicting $E = mc^2$, or just simply point out what is wrong with my thought process?