# APIによるカテゴリ作成エラー - ActiveRecord::ValueTooLong

**URL:** https://meta.discourse.org/t/cannot-create-category-by-api-activerecord-valuetoolong/143349
**Category:** Support
**Created:** [2020 年 3 月 4 日午後 10:08 UTC](https://meta.discourse.org/t/cannot-create-category-by-api-activerecord-valuetoolong/143349 "2020-03-04T22:08:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Amethi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amethi/32/88690_2.png) [@Amethi](https://meta.discourse.org/u/Amethi)
#### Post date: [2020 年 3 月 4 日午後 10:08 UTC](https://meta.discourse.org/t/cannot-create-category-by-api-activerecord-valuetoolong/143349/1 "2020-03-04T22:08:56Z")

</div>

カテゴリの作成を API で試みたところ、Internal Server Error のレスポンスが返されました。エラーログセクションを確認すると、カテゴリ作成を試みるたびに以下のエラーが繰り返し発生していることがわかります：

`ActiveRecord::ValueTooLong (PG::StringDataRightTruncation: ERROR: value too long for type character varying(6) ) /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.1.6/lib/patches/`

これはかなり明白に見えますよね？しかし、私のリクエストは以下の通りです：

```
Method: POST, RequestUri: 'https://xxx/categories', Version: 1.1, Content: System.Net.Http.MultipartFormDataContent, Headers:
{
  Api-Key: xxx
  Api-Username: xxx
  Accept: application/json
  User-Agent: lb-legacy-content-migrator
  Content-Type: multipart/form-data; boundary="f86b1fe9-5a87-4794-b949-8c0fb1347cb5"
}:[
  {
    "Key": "name",
    "Value": "Features"
  },
  {
    "Key": "color",
    "Value": "#ee00da"
  },
  {
    "Key": "text_color",
    "Value": "#000000"
  },
  {
    "Key": "skip_validations",
    "Value": "true"
  }
]

```

`skip_validations` パラメータを省略してみましたが、状況は変わりませんでした。  
他のオブジェクトの作成は問題なく行えています。

この問題の原因として考えられることは何か、ご存知ありませんか？

---

<div class="post-metadata">

### Author: ![justin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin/32/157614_2.png) [@justin](https://meta.discourse.org/u/justin)
#### Post date: [2020 年 3 月 4 日午後 10:13 UTC](https://meta.discourse.org/t/cannot-create-category-by-api-activerecord-valuetoolong/143349/2 "2020-03-04T22:13:26Z")

</div>

ハッシュ記号（#）なしで16進色の値を送信してみましたか？値が長すぎるというエラーが出ており、数字の6が含まれているため、コードを深く掘り下げない限り、それが私の印象です。

---

<div class="post-metadata">

### Author: ![Amethi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amethi/32/88690_2.png) [@Amethi](https://meta.discourse.org/u/Amethi)
#### Post date: [2020 年 3 月 5 日午後 7:38 UTC](https://meta.discourse.org/t/cannot-create-category-by-api-activerecord-valuetoolong/143349/3 "2020-03-05T19:38:06Z")

</div>

これで問題解決しました。はっきりわかりました。ありがとうございます 🙂

---

<div class="post-metadata">

### Author: ![justin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin/32/157614_2.png) [@justin](https://meta.discourse.org/u/justin)
#### Post date: [2020 年 3 月 5 日午後 8:22 UTC](https://meta.discourse.org/t/cannot-create-category-by-api-activerecord-valuetoolong/143349/4 "2020-03-05T20:22:22Z")

</div>


