# Can't insert a data in my collection from UI

**URL:** <https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637>\
**Category:** Help me!\
**Created:** [May 5, 2022, 9:25am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637 "2022-05-05T09:25:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [May 5, 2022, 9:25am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/1 "2022-05-05T09:25:28Z")

</div>

![Screenshot from 2022-05-05 10-06-48](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/2d142f87487d089d43a7812b8703a57a84132147.jpeg)

## Feature(s) impacted

Insert data

## Observed behavior

Can’t insert data, I put an ID bu the UI tell me that I don’t put ID

## Expected behavior

Data should be inserted

## Failure Logs

When I check the request payload by inspecting element on my browser, effectively, the id is not pass

```javascript
{data: {relationships: {category: {data: {type: "softwareCategoryV2s", id: "30948"}},…},…}}
data: {relationships: {category: {data: {type: "softwareCategoryV2s", id: "30948"}},…},…}
relationships: {category: {data: {type: "softwareCategoryV2s", id: "30948"}},…}
category: {data: {type: "softwareCategoryV2s", id: "30948"}}
product: {data: {type: "softwareProductV2s", id: "176079"}}
type: "softwareProductCategoriesV2s"

```

## Context

Can’t insert a data in a collection

- Project name: Uniseed
- Team name: …
- Environment name: …
- Agent type & version: …
- Recent changes made on your end if any: …

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [May 6, 2022, 9:14am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/3 "2022-05-06T09:14:47Z")

</div>

Hello @Charles_Touret,

Thanks for your message! 🙌

The widget you’re are using here (called “belongsTo typeahead”) is working this way:

- you type some characters
- it loads a list of related records matching these characters
- you pick the one you want by clicking on it

Meaning that: if you don’t pick one, none are selected.  
Do you see what I mean?  
If it’s not clear or if you think your problem is different, could you please share a little screencast with me?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [May 6, 2022, 1:33pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/4 "2022-05-06T13:33:03Z")

</div>

Yes I think you don’t understand the problem !  
I know how it works and there is already a screen cast on the post haha, you can see that I well pick the two fields Category and Product via the UI, but the UI also ask me the id (I think it should not ask me the id field because it’s the primary Key and it is auto generated in my db), and when I input an ID, the UI tell me that id cannot be null, but I put an ID !

We can call I you want and I can share you my screen in live 🙂

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [May 6, 2022, 2:01pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/5 "2022-05-06T14:01:53Z")

</div>

@Charles_Touret thanks for your answer.

I don’t see any screencast, only a screenshot, do you confirm?  
I would need a video of your screen to understand exactly what you’re trying to do and what’s failing.

Thanks!

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [May 6, 2022, 2:05pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/6 "2022-05-06T14:05:31Z")

</div>

annnh ok ! I send you that in few minutes sorry ! 🙂

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [May 10, 2022, 7:42am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/7 "2022-05-10T07:42:47Z")

</div>

@Charles_Touret any news? 🙂

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [June 21, 2022, 7:09pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/8 "2022-06-21T19:09:08Z")

</div>

Sill same problem 😕

the problem occurs when the collection contains two foreign key (join table)

 ![Screenshot from 2022-06-21 21-10-20](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/a/a412d87d6ef35fa0f5690a3374eb6999278db987.png)

On this screen it’s another collection but same problem

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [June 27, 2022, 1:18pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/9 "2022-06-27T13:18:01Z")

</div>

Hello @Charles_Touret,

Sorry for the delay and thanks for your answer.

Ok, now I think I understand your issue correctly.  
Just one silly question: is it normal that you need to define the id of your new record in the UI? Shouldn’t it be defined by your server?

Anyway, I think I can reproduce your problem: if you create a record and specify only the id attribute (relationships excluded), then the id is not sent… But if you specify any other attribute, the id is sent.  
I’m opening a bug report as of now, and I’ll let you know once it’s fixed.

Thanks again for the report and your patience 🙌

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 7, 2022, 7:17am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/10 "2022-07-07T07:17:03Z")

</div>

Hey @anon34731316 , yes the id is supposed to be auto generated by my backend, the id is not mentioned in my collection code, but forest UI ask me to add one, and never send, I think you well understood the problem ! Let me know about it 😕

---

<div class="post-metadata">

**Author:** ![shohanr](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/shohanr/32/4999_2.png) [@shohanr](https://community.forestadmin.com/u/shohanr)\
**Post date:** [July 7, 2022, 7:57am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/11 "2022-07-07T07:57:10Z")

</div>

The fix is being deployed.  
Thanks for your patience @Charles_Touret

Have a good day !

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 7, 2022, 8:28am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/12 "2022-07-07T08:28:06Z")

</div>

How can we access the fix ? is there a package to update ?

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [July 7, 2022, 9:12am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/13 "2022-07-07T09:12:23Z")

</div>

@Charles_Touret if you don’t want to be asked to fill the `id`, would it be satisfying to set this field as `read only` (in its settings)?

The fix mentioned by @shohanr is available without any package to update.  
Just refresh your browser and retry the creation: the given id should be sent within the payload!

Thanks.

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 8, 2022, 8:33am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/14 "2022-07-08T08:33:59Z")

</div>

It is still not working in my project you can see it there →

 ![Screenshot from 2022-07-08 10-33-18](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/a/a974be5b0728d3bbee3899315343e4f6727741b8.png)

The behaviour should be `insert into UserRole(roleId, userId) values (1,1);`

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [July 8, 2022, 8:57am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/15 "2022-07-08T08:57:56Z")

</div>

@Charles_Touret,

In the case you are bringing up, you are not giving any `id`.  
So it’s your backend/DB responsibility to attribute this `id` - it’s normal that you are not receiving the id from the frontend in your case!

What is your DB type? Did you define a sequence on the id attribute of this table?

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 8, 2022, 9:29am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/16 "2022-07-08T09:29:52Z")

</div>

This is not a problem with my db, this sql request is working → `insert into UserRole(roleId, userId) values (1,1);` and you can see that I don’t give the userRole.id in my request, it is auto generated

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 8, 2022, 9:30am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/17 "2022-07-08T09:30:54Z")

</div>

my db type is MYSQL,

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [July 8, 2022, 9:37am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/18 "2022-07-08T09:37:42Z")

</div>

I’m not sure I understand:

- `insert into UserRole(roleId, userId) values (1,1);` is working fine on your DB?
- But the request automatically created by your admin backend is not working? Can you check what is it exactly?

What’s sure is that your issue is not coming from the payload sent by the frontend anymore (it is not expected to send the `id` as you don’t provide it).

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 8, 2022, 9:54am UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/19 "2022-07-08T09:54:33Z")

</div>

- `insert into UserRole(roleId, userId) values (1,1);` is working fine on your DB?  
Yes this is working when I do the request manually in sql

I think I found what is not working from the UI,  
 → When I put the field in read\_only from the UI, the field is not send and I have a message telling me “you have to put a UserRole.id” and this sql request insert into UserRole(roleId, userId) values (1,1) is not done.

→ When I put the field id in editable from the UI, I can put an id, the field is sent and the request INSERT INTO `UserRole` (`id`,`roleId`,`userId`) VALUES(…) is done.

So I think there is still bug on the id autogeneration, or maybe there is something I can do in my model to autogenerate the id from the ui ?

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [July 8, 2022, 12:46pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/20 "2022-07-08T12:46:25Z")

</div>

> [@Charles\_Touret](#):
>
> message telling me “you have to put a UserRole.id”

Where do you have this message? In your admin backend console?  
Can you see the request / SQL query that is generating this error?

Again, it’s not the UI job to give you the id in this configuration. Either your model or directly your DB should do it when missing.

---

<div class="post-metadata">

**Author:** ![Charles\_Touret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/charles_touret/32/4381_2.png) [@Charles\_Touret](https://community.forestadmin.com/u/Charles_Touret)\
**Post date:** [July 8, 2022, 12:53pm UTC](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637/21 "2022-07-08T12:53:59Z")

</div>

I have this message in the UI ! and in the admin backend console I only have  
"POST /forest/userRole?timezone=Europe%2FZurich 422 106 - 6.657 ms

[Next page](https://community.forestadmin.com/t/cant-insert-a-data-in-my-collection-from-ui/4637.md?page=2)
