If you've just started using sequelize and sequelize CLI in development, you definitely had frequent addition and deletions of columns. And yeah, a...
For further actions, you may consider blocking this person and/or reporting abuse
for sequelize 6.3.0 version -
$ sequelize migration:create --name name_of_your_migration
this command is not working for create a migration file, then you can use-
$ sequelize migration:generate --name name_of_your_migration
What if all I need to do is change the attribute name, like april, to something different?
Hi @phillipiscoding my bad, I didn't get notified about this comment.
To change the attribute name, you use the renameColumn method, this is an example below:
module.exports = {
up: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.renameColumn('users', 'april', 'new_column_name'),
]);
}
down: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.renameColumn('users', 'new_column_name', 'april'),
]);
},
}
How to perform soft delete in sequelize?
Hi Hitarth1, you need to define a model as a paranoid. You can do that by passing the
paranoid: true
option when you're defining your model. And make suretimestamps
is not false. Paranoid needs timestamp to work.don't forget to add deletedAt column
Thanks, your information. this help me a lot
Thank you
Hi i am having trouble adding boolean column, i am able to add the column but unable to insert the value into the column
Can you provide an example for it please
Hi @Vam, here is an example.
To add a Boolean column(Model):
To insert a value into the column:
By default, it will always be
False
, but if you want to change it totrue
, passtrue
as the value. I mean a booleantrue
example:
User.create({
is_activated: true
});
Hi @vam, here is an example.
To add a Boolean column(Model):
To insert a value into the column:
By default, it will always be
False
, but if you want to change it totrue
, passtrue
as the value. I mean a booleantrue
example:
User.create({
is_activated: true
});
Thank you. This was helpful. Keep it up