【发布时间】:2021-06-03 09:43:12
【问题描述】:
我在尝试发布新记录时遇到问题。
我有一个使用 Strapi 的旧版应用程序,所以我没有让 Strapi 创建表格,它只使用 DDBB 上的内容。
这个集合类型之一:(enfermedadrepeticion) (go to repeticion_id)
{
"kind": "collectionType",
"connection": "atdbconnection",
"collectionName": "enfermedadrepeticion",
"info": {
"name": "RepeticionEnfermedad"
},
"options": {
"increments": false,
"timestamps": false
},
"attributes": {
"valor": {
"type": "decimal"
},
"enfermedad_id": {
"type": "integer"
},
"valor_1": {
"type": "string"
},
"valor_2": {
"type": "string"
},
"fechaTomaDato": {
"type": "string"
},
"repeticion_id": {
"via": "repeticion_enfermedads",
"model": "repeticion"
}
}
}
这是模型“repeticion”...转到 repeticion_enfermedads...
{
"kind": "collectionType",
"connection": "atdbconnection",
"collectionName": "repeticiones",
"info": {
"name": "Repeticion"
},
"options": {
"increments": false,
"timestamps": false
},
"attributes": {
"activa": {
"type": "boolean"
},
"altura": {
"type": "string"
},
"linea_id": {
"model": "linea"
},
"ensayo_id": {
"type": "integer"
},
"esp": {
"type": "string"
},
... bunch of fields ...
"repeticion_enfermedads": {
"collection": "repeticion-enfermedad",
"via": "repeticion_id"
}
}
}
我的关系是:一个Repeticion有0或N个repetition-enfermedad,通过repeticion_id字段。
使用这种关系,当我从“Repeticion”获取数据时,我会得到一个或多个“Repeticion-Enfermedad”。
所以,当我需要更新“Repeticion-Enfermedad”中的 una 条目时,我会使用此正文输入数据:
body {
enfermedad_id: 1,
fechaTomaDato: '2021-05-05 03:29:29',
fechaUltCambio: '2021-05-05 03:29:29',
repeticion_id: { id: 392571 },
valor: 60,
valor_1: '60',
valor_2: 'S'
}
一切正常!!
但是当我尝试使用 POST 创建记录时,使用相同的正文,我收到 500 错误。
error 错误:ER_NO_DEFAULT_FOR_FIELD:字段“repeticion_id”没有默认值
我尝试使用 Swagger 发送正文,但我得到了同样的错误。
我尝试发送“repeticion_id”字段,使用整数、字符串、对象等,但我无法让它工作......
我的 Strapi 版本是 3.0.6 我真的不想改变模型定义,它工作正常......
有什么建议吗??
最好的问候
【问题讨论】:
标签: relational-database strapi