Created a model using:
sequelize-cli model:create --name User --attributes "dispName:string,email:string,phoneNum1:string,vendorId:integer"
Which resulted in the following migration:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
dispName: {
type: Sequelize.STRING
},
// plus others...
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Users');
}
};
I want to change the automatically defined ID to:
cognitoId: {
allowNull: false,
primaryKey: true,
type: Sequelize.STRING(100)
}
So:
- Will sequelize be able to recognize this as the ID?
- Where all do I need to make this change? I could only identify the migration file.
- The model file doesn't have a definition for the
cognitoId
(or the original auto-generatedid
field): how will I be able to get the value of aUser
instance'scognitoId
(in the data returned by queries)? - Will changing the auto-generated
id
field have repercussions down the line? - Is the field name
id
"magical"? I.e., does the primary key have to be namedid
? - Is there a better way to do this?
- Will changing the types of the fields from
Sequelize.STRING
toSequelize.STRING(100)
create any issues down the line? - Why doesn't the models file generated by sequelize-cli have the
id
field defined?
When generating models+migrations from the command-line I couldn't find any syntax to specify the ID or any other customization for the fields.
Using:
[Node: 12.14.1, CLI: 5.5.1, ORM: 5.21.3]
PS: relatively new to NodeJS & completely new to Sequelize.