Sails API 获取错误 (500) ER_BAD_FIELD_ERROR
Sails API fetch error (500) ER_BAD_FIELD_ERROR
我是帆船初学者,我正在尝试使用帆船和 mysql 创建我的第一个 API。我尝试在我的 mysql 控制台中创建 table 并对 configuration.js 文件进行配置,并尝试在 chrome 浏览器中从 POSTMAN 访问 API。我从 sails 服务器收到以下错误。我的查询没有该字段,不确定这些字段是否是标准字段并附加在查询中,也不确定如何将这些字段自动创建为 table 的一部分。
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'message.createdAt' in 'field list'
at Query.Sequence._packetToError (C:\MyApi\node_modules\sails-mysql\node_mod
ules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Query.ErrorPacket (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\sequences\Query.js:82:18)
at Protocol._parsePacket (C:\MyApi\node_modules\sails-mysql\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\
lib\Connection.js:82:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:529:21)
--------------------
at Protocol._enqueue (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\Protocol.js:135:48)
at PoolConnection.Connection.query (C:\MyApi\node_modules\sails-mysql\node_m
odules\mysql\lib\Connection.js:185:25)
at __FIND__ (C:\MyApi\node_modules\sails-mysql\lib\adapter.js:836:20)
at afterwards (C:\MyApi\node_modules\sails-mysql\lib\connections\spawn.js:84
:5)
at C:\MyApi\node_modules\sails-mysql\lib\connections\spawn.js:40:7
at Ping.onPing [as _callback] (C:\MyApi\node_modules\sails-mysql\node_module
s\mysql\lib\Pool.js:94:5)
at Ping.Sequence.end (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\sequences\Sequence.js:96:24)
at Ping.Sequence.OkPacket (C:\MyApi\node_modules\sails-mysql\node_modules\my
sql\lib\protocol\sequences\Sequence.js:105:8)
at Protocol._parsePacket (C:\MyApi\node_modules\sails-mysql\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\
lib\Connection.js:82:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
Details: Error: ER_BAD_FIELD_ERROR: Unknown column 'message.createdAt' in 'fiel
d list'
但我收到上述错误,下面是我的 table.
mysql> desc message
-> ;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| id | int(4) | NO | PRI | NULL | auto_increment |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.03 sec)
我在模型 message.js
中有以下代码
module.exports = {
connection: 'someMysqlServer',
attributes: {
name: { type: 'string',
required: true}
}
};
您似乎在该连接上设置了 migrate: safe
,这意味着 Sails 无法更改您创建的 MySQL table。这很好,除了 Sails 查询包括迁移器通常添加的 createdAt
和 updatedAt
字段。您可以手动将这些列添加到 table(使用 datetime
类型)或将以下内容添加到您的模型配置中:
autoCreatedAt: false,
autoUpdatedAt: false
有关这些字段的更多信息in the docs。
当 liftng 航行时,它会提示输入数字 1 表示安全 2 用于类似的实验..选择 2 它会起作用..对我有用..
我是帆船初学者,我正在尝试使用帆船和 mysql 创建我的第一个 API。我尝试在我的 mysql 控制台中创建 table 并对 configuration.js 文件进行配置,并尝试在 chrome 浏览器中从 POSTMAN 访问 API。我从 sails 服务器收到以下错误。我的查询没有该字段,不确定这些字段是否是标准字段并附加在查询中,也不确定如何将这些字段自动创建为 table 的一部分。
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'message.createdAt' in 'field list'
at Query.Sequence._packetToError (C:\MyApi\node_modules\sails-mysql\node_mod
ules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Query.ErrorPacket (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\sequences\Query.js:82:18)
at Protocol._parsePacket (C:\MyApi\node_modules\sails-mysql\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\
lib\Connection.js:82:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:529:21)
--------------------
at Protocol._enqueue (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\Protocol.js:135:48)
at PoolConnection.Connection.query (C:\MyApi\node_modules\sails-mysql\node_m
odules\mysql\lib\Connection.js:185:25)
at __FIND__ (C:\MyApi\node_modules\sails-mysql\lib\adapter.js:836:20)
at afterwards (C:\MyApi\node_modules\sails-mysql\lib\connections\spawn.js:84
:5)
at C:\MyApi\node_modules\sails-mysql\lib\connections\spawn.js:40:7
at Ping.onPing [as _callback] (C:\MyApi\node_modules\sails-mysql\node_module
s\mysql\lib\Pool.js:94:5)
at Ping.Sequence.end (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\sequences\Sequence.js:96:24)
at Ping.Sequence.OkPacket (C:\MyApi\node_modules\sails-mysql\node_modules\my
sql\lib\protocol\sequences\Sequence.js:105:8)
at Protocol._parsePacket (C:\MyApi\node_modules\sails-mysql\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\
lib\Connection.js:82:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
Details: Error: ER_BAD_FIELD_ERROR: Unknown column 'message.createdAt' in 'fiel
d list'
但我收到上述错误,下面是我的 table.
mysql> desc message
-> ;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| id | int(4) | NO | PRI | NULL | auto_increment |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.03 sec)
我在模型 message.js
中有以下代码module.exports = {
connection: 'someMysqlServer',
attributes: {
name: { type: 'string',
required: true}
}
};
您似乎在该连接上设置了 migrate: safe
,这意味着 Sails 无法更改您创建的 MySQL table。这很好,除了 Sails 查询包括迁移器通常添加的 createdAt
和 updatedAt
字段。您可以手动将这些列添加到 table(使用 datetime
类型)或将以下内容添加到您的模型配置中:
autoCreatedAt: false,
autoUpdatedAt: false
有关这些字段的更多信息in the docs。
当 liftng 航行时,它会提示输入数字 1 表示安全 2 用于类似的实验..选择 2 它会起作用..对我有用..