Losing data when modifying a model

One thing that I find very worrying is the ease of losing data with simple changes in the models, how do you deal with that?

Strapi version 4.3.8

Is this local development or in production etc ?

while in development mode, sometimes when you change something in a model, the data is lost

For example, if you change a field name, using the Content type builder, it won’t change the database field, it will create a new one and all the date will be lost

Well that depends how you do it.
If the content type it will re-create the type not rename it indeed.
I THINK you can go into the schema.json file and just rename the type if it’s just a rename of the type and not a new type.

I did it, rename the name on the schema,json, it still creating a new field when the server reboots, and the old one is dropped from the database, leading to lose your data.

i’m working in my project a while to use it in production, and I’m really worried about it, when for any reason we need amend something and then lose something

best policy is to assume that all development data is ephemeral and keep backing up important data

1 Like

Yep, it’s mandatory…
How do you deal/execute your backups?

1 Like

4.6 + has DEITS you can check out

4.7 i think has a transfer tool too.

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.