Problem with insert
See original GitHub issueIssue type:
[X] Question [ ] Bug report [ ] Feature request [ ] Documentation issue
Database system/driver:
[ ] Postgres [ ] MSSQL [X] MySQL [ ] MariaDB [ ] SQLite3 [ ] Oracle [ ] Amazon Redshift
typed-knex version:
[X latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Knex.js version: Latest
Steps to reproduce or a small repository showing the problem:
Hi ! I want to make a simple insertion with two models.
import { Column, Table } from '@wwwouter/typed-knex';
import { Email, UUID } from '../../ts/types/base.type';
@Table('user')
class UserDB {
@Column({ primary: true })
public id!: UUID;
@Column()
public firstname!: string;
@Column()
public lastname!: string;
@Column()
public email!: Email;
@Column()
public birthdate!: Date;
@Column()
public gender: 'M' | 'F' | 'N' = 'N';
@Column()
public created_at!: Date;
@Column()
public updated_at!: Date;
@Column()
public termsofuse: boolean = true;
@Column()
public active: boolean = true;
}
export default UserDB;
import { Column, Table } from '@wwwouter/typed-knex';
import User from './User.db.model';
import { Bcrypt, UUID } from '../../ts/types/base.type';
@Table('password')
class PasswordDB {
@Column({ primary: true })
public id!: UUID;
@Column()
public password!: Bcrypt;
@Column({ name: 'user_id' })
public user!: User;
@Column()
public created_at!: Date;
@Column()
public updated_at!: Date;
}
export default PasswordDB;
I just run :
await db.query(UserDB).insertItem(userDB);
await db.query(GroupDB).insertItem(groupDB);
userDB and groupDB are instances of UserDB and GroupDB. They are full and there is no misfiled attributes.
And I got :
Error: insert into `group` (`group_name`, `user_id`) values (0, {"gender":"N","termsofuse":true,"active":true,"id":"6dc9f9f9-ae34-4eef-8a33-6f514ec05c6e","firstname":"string","lastname":"string","email":"user@example.com","birthdate":"2020-10-08T13:51:50.489Z","created_at":"2020-10-08 16:11:18","updated_at":"2020-10-08 16:11:18"}) - Column count doesn't match value count at row 1
at Packet.asError (/........node_modules/mysql2/lib/packets/packet.js:712:17)
at Query.execute (......../node_modules/mysql2/lib/commands/command.js:28:26)
at Connection.handlePacket (/.........node_modules/mysql2/lib/connection.js:425:32)
at PacketParser.onPacket (/h........node_modules/mysql2/lib/connection.js:75:12)
at PacketParser.executeStart (/.........../node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.<anonymous> (/............./node_modules/mysql2/lib/connection.js:82:25)
at Socket.emit (events.js:314:20)
at Socket.EventEmitter.emit (domain.js:486:12)
at addChunk (_stream_readable.js:307:12)
at readableAddChunk (_stream_readable.js:282:9)
What can I do, to avoid to put the user object instead of just user.id ?
Thanks for your work !
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
mysql insert problem - Stack Overflow
ive got a really weird problem. i have no clue why its not working. i create an user and get the id and...
Read more >SQL INSERT Error – Q&A Hub | 365 Data Science
This error appears if you have already created another table, employees, where you have missed inserting data about the individual with id ...
Read more >Issue with INSERT data not being available for immediate ...
I've got an issue where it appears that data that I insert isn't available for an immediate SELECT statement executed by the same...
Read more >Search Insert Position - LeetCode
Search Insert Position - Given a sorted array of distinct integers and a target value, return the index if the target is found....
Read more >Where is the problem with my insert query? Am connecting to ...
I am trying to insert data into the data base every time the php script is run. The connection to database is establishing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
If you’d log the group object, you should see what’s going wrong.
group
should only contain the fields you want to insert in the database, souser_id
andgroup_name
. Right now theObject.assign
puts too much data in thegroup
object.I think something like this should work:
👍