Sodium Canister Upgrade deleted my state

I had some state in a canister deployed to Sodium, and I ran this command to update the frontend code while maintaining the state: dfx canister --network ic install --all --mode upgrade. But my state seems to have been wiped.


States are not preserved across upgrades by default. In Motoko, you can use the stable keywords to specify which variables to preserve: In Rust, you need to provide pre_upgrade and post_upgrade functions, see as an example.


I see, I don’t think the documentation mentioned that. The documentation makes it seems like an upgrade just reserves state automatically.

1 Like

Thanks for catching this,@lastmjs. This is an oversight and should definitely be mentioned in the documentation for upgrading a canister!

Please feel free to log issues like this if the docs repo too.