Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
Sequelize error - Perhaps you meant to reference the column \"chat_room_participants.users_id\".
Disini saya lagi coba membuat API create data pakai ORM dari nodejs yaitu sequelize. table yang dicreate ini punya relasi ke table users. tapi terdapat error seperti ini :
{
"name": "SequelizeDatabaseError",
"parent": {
"length": 185,
"name": "error",
"severity": "ERROR",
"code": "42703",
"hint": "Perhaps you meant to reference the column \"chat_room_participants.users_id\".",
"position": "166",
"file": "parse_relation.c",
"line": "3611",
"routine": "errorMissingColumn",
"sql": "INSERT INTO \"chat_room_participants\" (\"chat_rooms_id\",\"users_id\",\"created_at\") VALUES ($1,$2,$3) RETURNING \"id\",\"chat_rooms_id\",\"users_id\",\"created_at\",\"updated_at\",\"userId\",\"chatRoomId\";",
"parameters": [
"47",
"9555e5e3-ac2f-4bee-8f55-3deeeb9c93c2",
"2022-06-21 01:02:20"
]
},
"original": {
"length": 185,
"name": "error",
"severity": "ERROR",
"code": "42703",
"hint": "Perhaps you meant to reference the column \"chat_room_participants.users_id\".",
"position": "166",
"file": "parse_relation.c",
"line": "3611",
"routine": "errorMissingColumn",
"sql": "INSERT INTO \"chat_room_participants\" (\"chat_rooms_id\",\"users_id\",\"created_at\") VALUES ($1,$2,$3) RETURNING \"id\",\"chat_rooms_id\",\"users_id\",\"created_at\",\"updated_at\",\"userId\",\"chatRoomId\";",
"parameters": [
"47",
"9555e5e3-ac2f-4bee-8f55-3deeeb9c93c2",
"2022-06-21 01:02:20"
]
},
"sql": "INSERT INTO \"chat_room_participants\" (\"chat_rooms_id\",\"users_id\",\"created_at\") VALUES ($1,$2,$3) RETURNING \"id\",\"chat_rooms_id\",\"users_id\",\"created_at\",\"updated_at\",\"userId\",\"chatRoomId\";",
"parameters": [
"47",
"9555e5e3-ac2f-4bee-8f55-3deeeb9c93c2",
"2022-06-21 01:02:20"
],
"level": "error"
}
ini kode setup associationnya :
db.user = require('./user.model')(sequelize)
db.chat_room = require('./chat_room.model')(sequelize)
db.chat_detail = require('./chat_detail.model')(sequelize)
db.chat_attachment = require('./chat_attachment.model')(sequelize)
db.chat_room_participant = require('./chat_room_participant.model')(sequelize)
db.user.hasMany(db.chat_room_participant, { as: 'participant_users' })
db.chat_room_participant.belongsTo(db.user, {
foreignKey: 'users_id'
})
db.user.hasMany(db.chat_detail, { as: 'message_senders' })
db.chat_detail.belongsTo(db.user, {
foreignKey: 'message_sender'
})
db.user.hasMany(db.chat_detail, { as: 'message_owners' })
db.chat_detail.belongsTo(db.user, {
foreignKey: 'message_owner'
})
db.chat_room.hasMany(db.chat_detail, { as: 'chat_details' })
db.chat_detail.belongsTo(db.chat_room, {
foreignKey: 'chat_rooms_id'
})
db.chat_room.hasMany(db.chat_room_participant, { as: 'room_participants' })
db.chat_room_participant.belongsTo(db.chat_room, {
foreignKey: 'chat_rooms_id'
})
db.chat_attachment.hasOne(db.chat_detail, { as: 'chat_detail_attachment' })
db.chat_detail.belongsTo(db.chat_attachment, {
foreignKey: 'chat_attachments_id'
})
ini relasi tablenya :
image.png
mohon bantuannya temen" semua
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban