这是我的 Todo 模型结构:
Todo
- title (Text)
- description (Text)
- completed (Boolean)
- users_permissions_user (Relation with User from users-permissions)
User
- username (Text)
- email (Email)
- provider (Text)
- password (Password)
- resetPasswordToken (Text)
- confirmationToken (Text)
- confirmed (Boolean)
- blocked (Boolean)
- role (Relation with Role from users-permissions)
- todos (Relation with Todo)
I've tried to create a Todo with the following request body:
{
"data": {
"title": "Your Todo Title",
"description": "Your Todo Description",
"completed": false,
"users_permissions_user": {
"connect": [3] // Replace with the actual user ID
}
}
}
但我收到此错误:
{
"data": null,
"error": {
"status": 400,
"name": "ValidationError",
"message": "Invalid key users_permissions_user",
"details": {
"key": "users_permissions_user",
"path": "users_permissions_user",
"source": "body"
}
}
}
我也尝试过类似的变体:
{
"data": {
"title": "Your Todo Title",
"description": "Your Todo Description",
"completed": false,
"users_permissions_user": 3
}
}
并且:
{
"data": {
"title": "Your Todo Title",
"description": "Your Todo Description",
"completed": false,
"users_permissions_user": {
"id": 3
}
}
}
但我仍然遇到同样的错误。
在 Strapi v5 中创建期间如何正确地将用户与待办事项关联起来?我的模型配置或 API 请求中是否缺少某些内容?
检查
Users-permissions
中API Tokens
的权限,应该允许查找用户。