I need to add FK in the tables, I've tried it in the following way and I can not do it.
Index.html
db.Country = db.sequelize.import('../api/country/country.model');
db.City = db.sequelize.import('../api/city/city.model');
module.exports = db;
city.model.js
export default function (sequelize, DataTypes) {
var City = sequelize.define('City', {
_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: DataTypes.STRING,
info: DataTypes.STRING,
active: DataTypes.BOOLEAN
}, {
associate: function (db) {
City.belongsTo(db.Country);
}
});
return City;
}
country.model.js
export default function (sequelize, DataTypes) {
var Country = sequelize.define('Country', {
_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: DataTypes.STRING,
info: DataTypes.STRING
}, {
associate: function (db) {
Country.hasMany(db.City);
}
});
return Country;
}
PS: I'm using postgres