How to set up a default value on a row in new servers?

As the title says, I updated my server, before when creating a new column I could set a default value when creating a new row, now it is no longer possible, this default value was part of the logic of my application, how can I achieve this behavior?

You can achieve this by adding the cell value when the new row is created through your app.

Hi @Skanus

You can run a saving object query in your logic

const Monster = Moralis.Object.extend("Monster");
const monster = new Monster();

monster.set("strength", 1024);
monster.set("ownerName", "Aegon");
monster.set("canFly", true);

monster.save()
.then((monster) => {
  // Execute any logic that should take place after the object is saved.
  alert('New object created with objectId: ' + monster.id);
}, (error) => {
  // Execute any logic that should take place if the save fails.
  // error is a Moralis.Error with an error code and message.
  alert('Failed to create new object, with error code: ' + error.message);
});

Link: https://docs.moralis.io/moralis-server/database/objects#saving-objects

I know that the new dashboard interface removed that functionality, we didn’t fix it yet

1 Like

Would be very useful to change the column default value somehow.

Did you try now to see if it works?

It is possible to set the default value when adding a new column, but it’s not possible to change the default value if the column already exists.

Can you show your code on how you tried to edit.
Did you receive any error?

Usually you can not change the properties of a column that it was already created.

You can still use beforeSave to make an equivalent of setting a default value.