I have a map storage, which stores structures. I've just removed a field from the structure, should I write storage migration codes for that? Could substrate work with existing values without a migration?

1 Answer 1


Yes, you should.

The key thing to know is that you already have some encoded bytes of your struct in storage, and whenever a storage read operation is done on your map, the pallet needs to know how to decode the stored bytes back into a struct properly.

If you do not create a migration for your storage, then what would happen is that your storage read operations will fail, because the codec finds out that the encoded bytes do not decode back to your expected struct type.

  • but it seems works well after I remove a nullable (Option<u64>) field. Mar 12, 2022 at 2:14
  • 1
    probably you are actually getting corrupt data. it may be that the data can still be deserialized, but it will be deserialized incorrectly.
    – Shawn Tabrizi
    Mar 12, 2022 at 20:18
  • 1
    Or maybe because it's the last field of the struct, so removing it simply means you do not continue reading the next x bytes that decodes into an Option<u64>, however this is highly inadvisable to rely on because this is an implementation-defined behaviour. Mar 14, 2022 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.