所以我有两台服务器,两台服务器都有不同的操作系统,一台是 Ubuntu 17,另一台是 Debian 9 Minimal(之所以叫 Minimal 是因为我的托管服务只有这个或 Debian 7)。所以两台服务器都有相同的 html 文件、js 文件和 php 文件。每次我在 Ubuntu 服务器上启动我的应用程序时,都会收到此错误:
[2017-11-02 18:06:58.514] [ERROR] [default] - Strange error
[2017-11-02 18:06:58.515] [ERROR] [default] - { Error: ER_NO_DEFAULT_FOR_FIELD: Field 'pskinsurl' doesn't have a default value
at Query.Sequence._packetToError (/var/www/Bot/node_modules/mysql/lib/protoc ol/sequences/Sequence.js:52:14)
at Query.ErrorPacket (/var/www/Bot/node_modules/mysql/lib/protocol/sequences /Query.js:77:18)
at Protocol._parsePacket (/var/www/Bot/node_modules/mysql/lib/protocol/Proto col.js:279:23)
at Parser.write (/var/www/Bot/node_modules/mysql/lib/protocol/Parser.js:76:1 2)
at Protocol.write (/var/www/Bot/node_modules/mysql/lib/protocol/Protocol.js: 39:16)
at Socket.<anonymous> (/var/www/Bot/node_modules/mysql/lib/Connection.js:103 :28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
--------------------
at Protocol._enqueue (/var/www/Bot/node_modules/mysql/lib/protocol/Protocol. js:145:48)
at Connection.query (/var/www/Bot/node_modules/mysql/lib/Connection.js:208:2 5)
at Query._callback (/var/www/Bot/cf.js:3293:26)
at Query.Sequence.end (/var/www/Bot/node_modules/mysql/lib/protocol/sequence s/Sequence.js:88:24)
at Query._handleFinalResultPacket (/var/www/Bot/node_modules/mysql/lib/proto col/sequences/Query.js:139:8)
at Query.EofPacket (/var/www/Bot/node_modules/mysql/lib/protocol/sequences/Q uery.js:123:8)
at Protocol._parsePacket (/var/www/Bot/node_modules/mysql/lib/protocol/Proto col.js:279:23)
at Parser.write (/var/www/Bot/node_modules/mysql/lib/protocol/Parser.js:76:1 2)
at Protocol.write (/var/www/Bot/node_modules/mysql/lib/protocol/Protocol.js: 39:16)
at Socket.<anonymous> (/var/www/Bot/node_modules/mysql/lib/Connection.js:103 :28)
code: 'ER_NO_DEFAULT_FOR_FIELD',
errno: 1364,
sqlMessage: 'Field \'pskinsurl\' doesn\'t have a default value',
sqlState: 'HY000',
index: 0,
sql: 'INSERT INTO games SET expire = 1509662218, cassetids = \'12530890030\', csteamid = \'76561198114317007\', cname = \'KnottyCord\', cavatar = \'https://st eamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/1d/1d3f34eee812968fd5 548f36ee281265373ddf91_full.jpg\', cskinsurl = \'-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWw KGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsVFx5KAVo5PSkKV4xhfG fKTgVvIXlxNPSwaOmMLiGwzgJvJMniO-Zoo_z2wXg-EVvfSmtc78HsNoy\', cskinsnames = \'Gam ma 2 Case\', cskinsprices = \'0.03\', cskins = 1, ctp = 0.03, cpick = \'t\', tcr eated = 1509660418.494, hash = \'adb9037cfd700a24544d4d774189a223\', bot = \'bot 1\'' }
在 Debian 上我没有收到此错误。
所以最终我想使用 Ubuntu,因为我对它更熟悉。
谢谢。如果您需要更多信息,请问我。
PS:如果有人告诉我必须在代码中指定一个特定值,那当然不行,因为我的“机器人”会自行设置该值,因此该值必须为无。该值取决于用户正在做什么,并且有无数种可能性,无法为所有可能性编写一行代码。
答案1
问题表述得很明确:
字段“pskinsurl”没有默认值
您尝试在表中插入一条记录,但未指定上述字段的值,并且表定义中没有默认值。您观察到的两个服务器之间的差异可能来自您使用的数据库服务器或表定义的差异。因此您有 3 个选择:
- 在 INSERT 语句中为该字段添加一个值。
- 修改表的定义
- 确保在两台服务器上使用相同的数据库服务器。