npm i sequelize sequelize-cli mysql2
config 수정 : logging:false 하면 로그가 안보인다.
npx sequelize db:create -- db생성
npx sequelize model:generate --name User --attributes email:string,nickname:string,password:string -- 모델 생성
model과 migration 파일 수정(고유ID를 id로 저장하는데 우리는 다른 ID를 사용하기 위함)
model file의 id값에 primaryKey: true을 준다.
이후 migrationfile의 Id를 수정.
npx sequelize db:migrate - sequelize table생성.
관계있는 db끼리 associate 맺어주기
ex)
this.belongsTo(models.users, { foreignKey: 'authorID' })
this.hasMany(models.postings, { foreignKey: 'authorID' });
관계를 맺어서 정보를 가져올 땐
코드를 입력하include: [
// {
// model: users,
// attributes: ['nick'],
// }