sequelize change column 1

sequelize change column

queryInterface.changeColumn('Person', 'foo', {
  type: DataTypes.FLOAT,
  defaultValue: 3.14,
  allowNull: false
});

Here is what the above code is Doing:
1. We’re adding a new column called foo to the Person table.
2. We’re changing the type of the foo column to FLOAT.
3. We’re setting the default value of the foo column to 3.14.
4. We’re setting the foo column to not allow null values.

The changeColumn method takes two arguments:
1. The name of the table.
2. An object that describes the column.

The object that describes the column has three properties:
1. type: The type of the column.
2. defaultValue: The default value of the column.
3. allowNull: A boolean that determines if the column can have null values.

The changeColumn method returns a promise.

Instructions
1.
In the up method, change the type of the foo column to FLOAT.

2.
In the up method, set the default value of the foo column to 3.14.

3.
In the up method, set the foo column to not allow null values.

4.
In the down method, change the type of the foo column to STRING.

5.
In the down method, set the default value of the foo column to null.

6.
In the down method, set the foo column to allow null values.

*/

‘use strict’;
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.changeColumn(‘Person’, ‘foo’, {
type: Sequelize.FLOAT,
defaultValue: 3.14,
allowNull: false
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.changeColumn(‘Person’, ‘foo’, {
type: Sequelize.STRING,
defaultValue: null,
allowNull: true
});
}
};

Similar Posts