Losing data when modifying a model

There’s no problem here.

Renaming a field is what is called a non-compatible change. As long as you change your API definition, you’ll have destructive change. These type of changes should be handled with care and with multiple intermediate phasis.

Either you can use the migrations scripts and then create the new column or do a rename with your script, so that Strapi won’t have to do anything when upgrading the schema.

Or you can do it in multiple steps (spaced in time) :

  1. adding the new field + maintaining the old and new field in your client code (if not using strapi), or using strapi lifecycle to ensure both are maintained
  2. new release after a while that removes the old field and the compability code (lifecycle or else)

Strapi behavior here is totally fine and expected.

1 Like