balderdashy / balderdashy/sails
Primary key value equals to 0
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**Node version**: 16.17.0
**Sails version** _(sails)_: 1.5.3
**ORM hook version** _(sails-hook-orm)_: 4.0.2
**Sockets hook version** _(sails-hook-sockets)_: 2.0.3
**Grunt hook version** _(sails-hook-grunt)_: 5.0.0
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_: sails-mysql@3.0.0
Hi,
I'm currently upgrading sails from **0.12.1** to **1.5.3**, I managed to fix all the errors to start my application but now I got an error when I'm trying to find data from my DB using sails :
```
Unexpected error from database adapter: Could not find a primary key for a record.
Perhaps it wasn't selected in the query. The primary key was set to: et_id and the record returned was: RowDataPacket {
et_id: 0,
name: 'Default'
}
```
Here is my model:
```
module.exports = {
datastore: 'mysqlDB',
schema: true,
primaryKey: 'et_id',
attributes: {
et_id: {
type: 'integer',
autoIncrement: true,
unique: true,
},
name: {
type: 'string',
unique: true
}
}
```
I think the issue come from my id (et_id) because it has a value of 0 and it's a primary key. The problem is that I can't change this value, it must be 0 for my project and also the et_id must remain the primary key of my model (for other model associations)
Does any attribute exists in the model or something else to get rid of this error ?
Contributor guide
Research direction
Start with the model definition and the database-adapter error shown in the report, then reproduce the find operation against the record whose et_id is 0. Check how the adapter handles a zero-valued primary key. Done means the record can be retrieved without the primary-key error, or the limitation and required model or data change are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100