MySQL未处理的拒绝错误,无默认值

时间:2018-07-23 19:10:15

标签: mysql sql database reactjs phpmyadmin

我正在使用React Social Network框架,并在注册它后不断收到此错误。

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)

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您最有可能在(未指定的)表中插入一行,但是您忘记为列bio指定值。

因此,您试图在列null上插入bio值,并且很可能将此列定义为not null

解决方案?要么:

  1. 在插入之前在bio列上放置一些值。

  2. 更改表定义,并为列default添加一个bio值。