Creating new items for a collection(having relations) through STRAPI default API is not working

System Information
  • Strapi Version: v 3.4.1- Community Edition
  • Operating System: Ubuntu 16
  • Database: MySQL Ver 14.14
  • Node Version: v12.18.3
  • NPM Version: 6.14.6
  • Yarn Version: 1.22.4

Created two Collection type namely:

  1. Test_products.
  2. Test_colors.
    Have created a many-to-many relationship between Test_products & Test_colors.

Now I am trying to create the new entry in Test_products by calling the API /test_products & sending the following payload using POSTMAN

{ "name" : "Product-4", "test_colors" : [ { "color_name" : "blue" } ] }

In response getting the following error:

{ "statusCode": 500, "error": "Internal Server Error", "message": "An internal server error occurred" }

Getting following error logs in console:

[2020-12-28T11:51:19.034Z] error Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect integer value: ‘[object Object]’ for column ‘test-color_id’ at row 1 at Query.Sequence._packetToError (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14) at Query.ErrorPacket (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/sequences/Query.js:79:18) at Protocol._parsePacket (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/Protocol.js:291:23) at Parser._parsePacket (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/Parser.js:433:10) at Parser.write (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/Parser.js:43:10) at Protocol.write (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/Protocol.js:38:16) at Socket. (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/Connection.js:88:28) at Socket. (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/Connection.js:526:10) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at TCP.onStreamRead (internal/stream_base_commons.js:186:23) at Protocol._enqueue (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/protocol/Protocol.js:144:48) at Connection.query (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/mysql/lib/Connection.js:198:25) at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/dialects/mysql/index.js:130:18 From previous event: at Client_MySQL._query (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/dialects/mysql/index.js:124:12) at Client_MySQL.query (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/client.js:158:17) at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/transaction.js:331:24 From previous event: at Client_MySQL.trxClient.query (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/transaction.js:326:12) at Runner.query (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/runner.js:135:36) at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/runner.js:39:23 From previous event: at Runner.run (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/runner.js:25:16) at Builder.Target.then (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/knex/lib/interface.js:14:43) at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:900:35 at processImmediate (internal/timers.js:456:21) From previous event: at Child. (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:899:62) From previous event: at Child. (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:840:36) From previous event: at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:797:43 at arrayEach (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/node_modules/lodash/lodash.js:516:11) at Function.forEach (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/node_modules/lodash/lodash.js:9368:14) at Child. (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:797:7) From previous event: at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:693:24 From previous event: at Child.attach (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/bookshelf/lib/relation.js:693:8) at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/strapi-connector-bookshelf/lib/relations.js:234:36 at processImmediate (internal/timers.js:456:21) From previous event: at /home/neeraj/strapi-learning/strapi-neeraj/node_modules/strapi-connector-bookshelf/lib/relations.js:234:14 at Array.reduce () at Function.update [as updateRelations] (/home/neeraj/strapi-learning/strapi-neeraj/node_modules/strapi-connector-bookshelf/lib/relations.js:105:68) [2020-12-28T11:51:19.038Z] debug POST /test-products (112 ms) 500

Please guide me on how to create the new entry in the collection type having the relation with the other collections


We don’t currently support nested relational creation, you will need to make a post request to test_colors, grab the IDs and send a POST/PUT on the test_products with an array of the ids.

how can I customize sending code filed instead of IDs for the relation