await queryInterface.addColumn('urls', 'userId', Sequelize.INTEGER);
await queryInterface.addConstraint('urls', {
fields: ['userId'],
type: 'foreign key',
name: 'FK_any_name_you_want',
references: {
table: 'users',
field: 'id'
},
onDelete: 'cascade',
onUpdate: 'cascade'
});
migration을 통해
1. column 추가
2. constraint 추가
class Video extends Model {}
Video.init({
title: Sequelize.STRING,
sequence: Sequelize.INTEGER,
description: Sequelize.TEXT,
// set relationship (hasOne) with `Series`
seriesId: {
type: DataTypes.INTEGER,
references: {
model: Series, // Can be both a string representing the table name or a Sequelize model
key: 'id'
}
}
}, { sequelize, modelName: 'video' });
addConstraint를 이용해서 추가하는 것이 더 상세하게 조건들을 넣을 수 있다.