# CUID as my id isnt letting me create a data entry

**URL:** <https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233>\
**Category:** Help me!\
**Tags:** database-schema\
**Created:** [May 3, 2023, 7:22am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233 "2023-05-03T07:22:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Geokgeuzian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/albert_geokgeuzian/32/6063_2.png) [@Albert\_Geokgeuzian](https://community.forestadmin.com/u/Albert_Geokgeuzian)\
**Post date:** [May 3, 2023, 7:22am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233/1 "2023-05-03T07:22:22Z")

</div>

I am having an issue when creating a new user in one of my tables.  
My id is set as a cuid: id String @id @default(cuid()) ← from Prisma Schema

when creating a new entry on my table, i am getting an error for trying to create a new entry with a null id.

Given that the creation of the id is handled by the database itself, I expect forest admin to create the new data entry without any issue and allow the database to handle the id generation on its own

errror message: null value in column “id” of relation “Psychologist” violates not-null constraint

## Context

- Project name: Zenith
- Team name: Zenith
- Environment name: Development
- Agent (forest package) name & version: “@forestadmin/agent” : “^1.8.8”
- Database type: SQL, PostgresSQL
- Recent changes made on your end if any: this hasnt worked since the start

---

<div class="post-metadata">

**Author:** ![anon39940173](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon39940173](https://community.forestadmin.com/u/anon39940173)\
**Post date:** [May 3, 2023, 7:28am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233/2 "2023-05-03T07:28:21Z")

</div>

This is known, autogenerated ids need work on our side.  
I’ll bump the priority of the ticket

Can you attempt to add the following code to your agent in the meantime?

```javascript
agent.customizeCollection('user', users => {
  users.addHook('Before', 'Create', async (context) => {
    context.data.forEach((user) => {
      delete user.id;
    })
  })
})

```

---

<div class="post-metadata">

**Author:** ![Albert\_Geokgeuzian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/albert_geokgeuzian/32/6063_2.png) [@Albert\_Geokgeuzian](https://community.forestadmin.com/u/Albert_Geokgeuzian)\
**Post date:** [May 3, 2023, 7:36am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233/3 "2023-05-03T07:36:09Z")

</div>

Hello, thank you for your reply.

I added the code however i am still not able to create a user, and it is giving me the same error

error: null value in column “id” of relation “Psychologist” violates not-null constraint

this is my collection currently

```javascript

export const psychologistCollection = (
  collection: CollectionCustomizer<TSchema, "Psychologist">,
) => {
  collection.addHook("Before", "Create", async (context) => {
    context.data.forEach((user) => {
      delete user.id;
    });
  });
};

```

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [May 3, 2023, 7:43am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233/4 "2023-05-03T07:43:24Z")

</div>

Hey @Albert_Geokgeuzian and welcome to our community 👋

Could you confirm that the `id` entry is generated by your database and not by Prisma (By sharing the DDL of your table here/by DM if you consider it private)?

Could you also confirm that the `id` field is marked as read-only on your admin-panel side?

---

<div class="post-metadata">

**Author:** ![Albert\_Geokgeuzian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/albert_geokgeuzian/32/6063_2.png) [@Albert\_Geokgeuzian](https://community.forestadmin.com/u/Albert_Geokgeuzian)\
**Post date:** [May 3, 2023, 7:50am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233/5 "2023-05-03T07:50:10Z")

</div>

> [@anon39940173](#):
>
> ```javascript
> gent.customizeCollection('user', users => {
> users.addHook('Before', 'Create', async (context) => {
> context.data.forEach((user) => {
> delete user.id;
> })
> })
> 
> ```

Thank you for your help. I had missed the fact that my ids are generated by Prisma and not the database. I will switch my ids to autoincremented.

---

<div class="post-metadata">

**Author:** ![anon39940173](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon39940173](https://community.forestadmin.com/u/anon39940173)\
**Post date:** [May 3, 2023, 8:33am UTC](https://community.forestadmin.com/t/cuid-as-my-id-isnt-letting-me-create-a-data-entry/6233/6 "2023-05-03T08:33:29Z")

</div>

You can create the ids in the hook

```javascript
import { createId } from '@paralleldrive/cuid2';

agent.customizeCollection('user', users => {
  users.addHook('Before', 'Create', async (context) => {
    context.data.forEach((user) => {
      user.id = createId();
    })
  })

```
