balderdashy / balderdashy/sails
primary key id must have either required or autoIncrement set
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**Node version**:
10
**Sails version** _(sails)_:
1.2.2
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_:
sails-mongo@latest
When i put sails on production with sails-mongo (mongodb)
I get error from all models i've set.
Error: In model `call`, primary key `id` must have either `required` or `autoIncrement` set.
My model:
`module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
name: {
type: 'string',
required: true,
maxLength:120,
},
status: {
type: 'string',
isIn: ['open', 'closed'],
defaultsTo: 'open',
description: 'Status do chamado, será importante para a exibição e controle.'
},
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
department: {
model: 'department',
required: true,
},
companie:{
model: 'companie',
required: true,
},
messages: {
collection: 'message',
via: 'call',
},
user: {
model: 'user',
required: true,
},
agent: {
model: 'user',
},
},
};
`
my config/models.js
`id: { type: 'string', columnName: '_id' },`
Contributor guide
Research direction
Start with the model definition shown in the issue and config/models.js, then reproduce the production startup using sails-mongo. Trace why the primary key declaration is rejected when it maps id to _id, and verify that all affected models load without the validation error while retaining the intended MongoDB identifier mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, node.js
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100