I'm using a React Social Network framework and I keep getting this error after signing up on it.
Unhandled rejection Error: ER_NO_DEFAULT_FOR_FIELD: Field 'bio' doesn't have a default value
at Query.Sequence._packetToError (/var/www/example.com/public_html/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/var/www/example.com/public_html/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/var/www/example.com/public_html/node_modules/mysql/lib/protocol/Protocol.js:278:23)
at Parser.write (/var/www/example.com/public_html/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/var/www/example.com/public_html/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/var/www/example.com/public_html/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/var/www/example.com/public_html/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onread (net.js:638:20)
--------------------
at Protocol._enqueue (/var/www/example.com/public_html/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/var/www/example.com/public_html/node_modules/mysql/lib/Connection.js:200:25)
at bcrypt.hash (/var/www/example.com/public_html/models/db.js:18:10)
at /var/www/example.com/public_html/node_modules/bcrypt-nodejs/bCrypt.js:631:3
at process._tickCallback (internal/process/next_tick.js:61:11)
How do I fix this?
You most likely are inserting a row in a (an unspecified) table, but you forgot to specify the value for the column bio.
Therefore, you are trying to insert a null value on the column bio, and this columns is most likely defined as not null.
Solution? Either:
Put some value on the bio column before inserting.
Change the table definition and add a default value for the column bio.
Related
I'm using the MySQL module for NodeJS, however I keep getting the following error after approximately 10 requests to the database. I'm using the following code to connect to the DB:
var con = mysql.createConnection({
host: "10.37.100.15",
user: process.env.MYSQLUSR,
password: process.env.MYSQLPASSWD,
database: process.env.MYSQLDB
});
Then I use con.query(sqlStatement, function (err, result, fields) {<function>}). I already tried changing the max_allowed_packet to 500M on the server but this didn't fix the issue. This is the full error:
events.js:377
throw er; // Unhandled 'error' event
^
Error: Packets out of order. Got: 0 Expected: 3
at Parser._tryReadPacketHeader (/app/node_modules/mysql/lib/protocol/Parser.js:470:15)
at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:33:29)
at Protocol.write (/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:293:12)
at readableAddChunk (internal/streams/readable.js:267:9)
at Socket.Readable.push (internal/streams/readable.js:206:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:423:8)
at Protocol.emit (events.js:400:28)
at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.handleParserError (/app/node_modules/mysql/lib/protocol/Protocol.js:380:10)
at Parser._tryReadPacketHeader (/app/node_modules/mysql/lib/protocol/Parser.js:478:10)
at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:33:29)
[... lines matching original stack trace ...]
at Socket.emit (events.js:400:28) {
code: 'PROTOCOL_PACKETS_OUT_OF_ORDER',
fatal: true
}
default wait_timeout is 8 hrs.
I'd suspect the mysql-nodejs version isn't resetting the expected packet count on re-connection.
In a test environment you can reduce the wait_timeout.
It quite possibly is:
https://github.com/mysqljs/mysql/issues/2534
https://github.com/mysqljs/mysql/issues/2451
Last comment on #2534 is "I change my connection from mysql.createConnection to mysql.createPool, the error never happen again"
I already searched stackoverflow for like an hour, but no solution can solve my problem.
I want to run this code:
for (var skin in body){
connection.query(`IF NOT EXISTS(SELECT MarketName FROM Skins WHERE MarketName = ?);
THEN
INSERT INTO Skins (MarketName) VALUES (?);
END IF;`,[skin, skin]); }
But if I run this with nodejs, I get this error:
/var/www/html/bot/node_modules/mysql/lib/protocol/Parser.js:80
throw err; // Rethrow non-MySQL errors
^
Error: ER_PARSE_ERROR: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS(SELECT MarketName FROM
Skins WHERE MarketName = 'Nova | Moon in Li' at line 1
at Query.Sequence._packetToError (/var/www/html/bot/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
at Query.ErrorPacket (/var/www/html/bot/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/var/www/html/bot/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/var/www/html/bot/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/var/www/html/bot/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket. (/var/www/html/bot/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:266:12)
at readableAddChunk (_stream_readable.js:253:11)
--------------------
at Protocol._enqueue (/var/www/html/bot/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Connection.query (/var/www/html/bot/node_modules/mysql/lib/Connection.js:208:25)
at Request._callback (/var/www/html/bot/index.js:531:16)
at Request.self.callback (/var/www/html/bot/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request. (/var/www/html/bot/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage. (/var/www/html/bot/node_modules/request/request.js:1085:12)
I would appreciate your help.
MySQL only allows IF statements in programming blocks -- stored procedures, triggers, and the like.
The correct way to do what you want is to create a unique index or constraint on Skins(MarketName). That way, the database ensures integrity of the data. You can do this as:
create unique index unq_skins_marketname on Skins(MarketName);
Then, an attempt to insert a duplicate will result in an error. You can generally avoid this by doing:
insert into skins(marketname)
values (?)
on duplicate key marketname = values(marketname); -- this is a no-op
Here is my (very simple) code :
var connection = mysql.createConnection(infosDB);
connection.connect()
connection.query(`SELECT * FROM action`, function(err, data){
console.log(data);
})
The action table is not empty... I think my database is ok.
This code works very well for me on localhost.
However, I bought A2 Hosting to launch node.js (v6.10.3 on localhost and server) project and I get that error when I try to launch this simple code.
{ Error: Packets out of order. Got: 80 Expected: 0
at Parser.write (/home/hello1234/public_html/myapp/node_modules/mysql/lib/protocol/Parser.js:42:19)
at Protocol.write (/home/hello1234/public_html/myapp/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/hello1234/public_html/myapp/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
--------------------
at Protocol._enqueue (/home/hello1234/public_html/myapp/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/home/hello1234/public_html/myapp/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/home/hello1234/public_html/myapp/node_modules/mysql/lib/Connection.js:130:18)
at update_infos_all_users (/home/hello1234/public_html/myapp/app.js:570:9)
at Job.job (/home/westudec/public_html/myapp/app.js:1566:3)
at Job.invoke (/home/westudec/public_html/myapp/node_modules/node-schedule/lib/schedule.js:172:10)
at Timeout._onTimeout (/home/hello1234/public_html/myapp/node_modules/node-schedule/lib/schedule.js:542:11)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5) code: 'PROTOCOL_PACKETS_OUT_OF_ORDER', fatal: true }
The weird thing is that all work good on my computer.
Does someone have an idea ?
Thanks
For following code below:
var User = sequelize.define('User', {
providerIds: { type : DataTypes.ARRAY(DataTypes.STRING)}
}
I am getting following error:
Unhandled rejection SequelizeDatabaseError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[], `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `ReviewId` INT' at line 1
at Query.formatError (/media/mydata/projects/jobcuejs/node_modules/sequelize/lib/dialects/mysql/query.js:175:14)
at Query._callback (/media/mydata/projects/jobcuejs/node_modules/sequelize/lib/dialects/mysql/query.js:49:21)
at Query.Sequence.end (/media/mydata/projects/jobcuejs/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Query.ErrorPacket (/media/mydata/projects/jobcuejs/node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
at Protocol._parsePacket (/media/mydata/projects/jobcuejs/node_modules/mysql/lib/protocol/Protocol.js:280:23)
at Parser.write (/media/mydata/projects/jobcuejs/node_modules/mysql/lib/protocol/Parser.js:73:12)
at Protocol.write (/media/mydata/projects/jobcuejs/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/media/mydata/projects/jobcuejs/node_modules/mysql/lib/Connection.js:96:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)
What's wrong am I doing?
>mysql --version
mysql Ver 14.14 Distrib 5.6.28, for debian-linux-gnu (x86_64) using EditLine wrapper
An array of type, e.g. DataTypes.ARRAY(DataTypes.DECIMAL). Only available in postgres.
Visit http://docs.sequelizejs.com/en/latest/api/datatypes/?highlight=array#array
What kind of error is this?
Unhandled rejection SequelizeDatabaseError: ER_EMPTY_QUERY: Query was empty
at Query.formatError (node_modules/sequelize/lib/dialects/mysql/query.js:159:14)
at Query._callback (node_modules/sequelize/lib/dialects/mysql/query.js:35:21)
at Query.Sequence.end (node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Query.ErrorPacket (node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
at Protocol._parsePacket (node_modules/mysql/lib/protocol/Protocol.js:274:23)
at Parser.write (node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (node_modules/mysql/lib/Connection.js:96:28)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
I'm trying to update an entity with the following code:
db.Account.update({
'post_id': data.id
}, {
where: { id: account.id }
})
.spread(account => {
next();
});
but it doesn't work. Any idea?
The same issue I was facing and after a lot of debugging found out the silly mistake. The reason for me was in mysql added a column and forgot to add the same to sequelize model representing the same table so for your case also will suggest you to just double check for post_id is present in Account sequelize model.