I want to migrate this column:
countryId: {
type: Sequelize.DataTypes.CHAR(2),
allowNull: true,
references: {
model: 'country',
key: 'country_code'
},
field: 'country_id'
},
country_code:
countryCode: {
type: DataTypes.CHAR(2),
allowNull: false,
primaryKey: true,
field: 'country_code'
},
Full console.log:
CREATE TABLE IF NOT EXISTS `address` (`address_id` BIGINT NOT NULL
auto_increment , `state_id` INTEGER(11) UNIQUE, `country_id` CHAR(2),
PRIMARY KEY (`address_id`), FOREIGN KEY (`state_id`) REFERENCES
`province` (`province_id`), FOREIGN KEY (`country_id`) REFERENCES
`country` (`country_code`)) ENGINE=InnoDB;
But I get
ERROR: Cannot add foreign key constraint
When I add unique: true
to country_id
, it still doesn't work for some reason.