Thank you for the question. The answer depends on the kind of electoral system you have in place. Let me give you two alternatives.
One is an example with first past the post. The example is India, part of the same electoral system, heritage, and political institutional heritage that Canada also inherited as part of the Westminster family. The Indian integrity law, or part of the Indian constitution, simply requires.... It doesn't take away the freedom of the member of the lower house or the upper house to cross the floor, but if a member leaves the party on the ticket he or she got elected on, there has to be a by-election. For an independent, it doesn't say that. That's really important. The freedom of movement is not taken away; it simply carries the cost of defending or re-defending your turf in your new colour as a member of another party, or an independent, depending on how you want to fight in the by-election.
Another case would be Portugal, which is closed list proportional representation. It is a system I didn't address, but it's certainly on the menu. The constitution simply forbids it. If you are elected, because the voting is on clear party lines, you can't leave. If you want to leave the party on the list of which you got elected, you have to relinquish your seat. That's it. Then the next person on the list who didn't get elected gets promoted.
Things get to be more complex in other parts of the world. To keep it a little more manageable, I just wanted to give you the two ranges, if you will: pure PR and first past the post, and how they work with anti-floor-crossing legislation.