Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

define foreign key in sequelize migration

UserId: { // name of foreign key using naming convention
        type: Sequelize.DataTypes.INTEGER,
        references: {
          model: { tableName: 'Users' }, // provide table name
          key: 'id' // PK of the User Model
        },
        allowNull: false,
        onUpdate: 'cascade',
        onDelete: 'cascade',
},
 
PREVIOUS NEXT
Tagged: #define #foreign #key #sequelize #migration
ADD COMMENT
Topic
Name
3+9 =