* Add a constraint to a table * * Available constraints: * - UNIQUE * - DEFAULT (MSSQL only) * - CHECK (MySQL - Ignored by the database engine ) * - FOREIGN KEY * - PRIMARY KEY * * @example UNIQUE * queryInterface.addConstraint('Users', { * field
(tableName, options)
| 754 | * @returns {Promise} |
| 755 | */ |
| 756 | async addConstraint(tableName, options) { |
| 757 | if (!options.fields) { |
| 758 | throw new Error('Fields must be specified through options.fields'); |
| 759 | } |
| 760 | |
| 761 | if (!options.type) { |
| 762 | throw new Error('Constraint type must be specified through options.type'); |
| 763 | } |
| 764 | |
| 765 | options = Utils.cloneDeep(options); |
| 766 | |
| 767 | const sql = this.queryGenerator.addConstraintQuery(tableName, options); |
| 768 | return await this.sequelize.query(sql, options); |
| 769 | } |
| 770 | |
| 771 | async showConstraint(tableName, constraintName, options) { |
| 772 | const sql = this.queryGenerator.showConstraintsQuery(tableName, constraintName); |