Thanks in advance.
sorry if it is a silly mistake and i am new to sequlize
but i have 2 models in two different files
1st User
module.exports=(sequelize,DataTypes)=>{
const User=sequelize.define("User",{
email:{
type:DataTypes.STRING,
primaryKey:true,
allowNull:false,
validate:{
notEmpty:true
},
},
password:{
type:DataTypes.STRING,
allowNull:false,
validate:{
notEmpty:true
},
}
},
{
freezeTableName: true
}
)
return User;
};
2nd Section
module.exports=(sequelize,DataTypes)=>{
const Section=sequelize.define("Section",{
HeroSec:{
type:DataTypes.BOOLEAN,
defaultValue: true,
allowNull:false,
validate:{
notEmpty:true
},
}
},
{
freezeTableName: true
});
return Section;
}
i am trying to create a relationship between the two tables user and section with email as primary key as well as foreign key of the other
which is giving me errors after error
relationship code:
const Section = require("./Section");
const User = require("./User");
module.exports=(sequelize)=>{
User=sequelize.define(User)
Section=sequelize.define(Section)
User.hasOne(Section);
sequelize.sync({alter:true}).then(()=>{
//
}).catch((err)=>{
console.log(err)
})
};
plz help me to connect these two using email as key
sorry if it is a naive error
thanks 🙂
New contributor
Mayank Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3