不会出现外键

时间:2019-04-17 06:07:08

标签: node.js express sequelize.js

我使用续集创建了一个关联。

并引发查询,但是引用的外键仍然为空。

如果您能告诉我如何解决它,我将不胜感激。

db.User.belongsToMany(db.Album, { through: 'user_album', foreignKey: 'album_no' });
db.Album.belongsToMany(db.User, { through: 'user_album',foreignKey: 'User_no' });

db.Album.hasMany(db.Song, {foreignKey: 'album_no'});
db.Song.belongsTo(db.Album,{foreignKey: 'album_no'});

db.Song.hasMany(db.Song_contract, {foreignKey: 'song_no'});
db.Song_contract.belongsTo(db.Song,{foreignKey: 'song_no'});`

module.exports = (sequelize, DataTypes) => {
const album = sequelize.define('album', {
    album_no: {type: DataTypes.INTEGER, comment: "앨범등록번호", primaryKey: true, autoIncrement: true}
  , album_name: { type: DataTypes.STRING(45), comment: "앨범이름", }
  , album_img: { type: DataTypes.STRING(100), comment: "앨범이미지", }
  , album_code: { type: DataTypes.STRING(45), comment: "앨범코드", }
  , artist_name: { type: DataTypes.STRING(45), comment: "아티스트이름", }
  , album_agency: { type: DataTypes.STRING(45), comment: "기획사이름", }
  , album_distributor: { type: DataTypes.STRING(45), comment: "유통사이름" }
  , release_date: { type: DataTypes.STRING(8), comment: "발매일(YYYYMMDD)" }
  , virtual_account: { type: DataTypes.STRING(45), comment: "가상계좌번호",unique: true  }


}, {
    charset: 'utf8',
    collate: 'utf8_unicode_ci',
    timestamps: true,
  });

module.exports = (sequelize, DataTypes) => {
const song = sequelize.define('song', {
    song_no: {type: DataTypes.INTEGER, comment: "곡등록번호", primaryKey: true,autoIncrement: true}
  , song_code_1: { type: DataTypes.STRING(45), comment: "곡코드1", }
  , song_name_1: { type: DataTypes.STRING(45), comment: "곡이름1", }
  , song_code_2: { type: DataTypes.STRING(45), comment: "곡코드2", }
  , song_name_2: { type: DataTypes.STRING(45), comment: "곡이름2", }
  , song_code_3: { type: DataTypes.STRING(45), comment: "곡코드3", }
  , song_name_3: { type: DataTypes.STRING(45), comment: "곡이름3", }


}, {
  charset: 'utf8',
  collate: 'utf8_unicode_ci',
  timestamps: true,
  });

0 个答案:

没有答案