When I run the following command:
sequelize-cli model:create --name User --attributes "dispName:string,email:string,phoneNum1:string"
I end up with the following migration file:
'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
},
email: {
type: Sequelize.STRING
},
phoneNum1: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Users');
}
};
and the following model file:
'use strict';
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
dispName: DataTypes.STRING,
email: DataTypes.STRING,
phoneNum1: DataTypes.STRING
}, {});
User.associate = function(models) {
// associations can be defined here
};
return User;
};
Questions:
id
?Versions:
[Node: 12.14.1, CLI: 5.5.1, ORM: 5.21.3]
The following do not answer my question:
If you don't declare PK in your model sequelize assumes you have the id PK. This is by design. And yes you can rename your PK in the model. Just don't forget to setup PK in the mode properly according to a real PK in your DB.