# Adding a custom entity, but it does not work

**URL:** <https://discuss.konghq.com/t/adding-a-custom-entity-but-it-does-not-work/5180>\
**Category:** Questions\
**Created:** [December 19, 2019, 9:15pm UTC](https://discuss.konghq.com/t/adding-a-custom-entity-but-it-does-not-work/5180 "2019-12-19T21:15:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![1116](https://avatars.discourse-cdn.com/v4/letter/1/439d5e/32.png) [@1116](https://discuss.konghq.com/u/1116)\
**Post date:** [December 19, 2019, 9:15pm UTC](https://discuss.konghq.com/t/adding-a-custom-entity-but-it-does-not-work/5180/1 "2019-12-19T21:15:12Z")

</div>

I added a custom entity, and created the dao file as below.

```
-- daos.lua
local typedefs = require "kong.db.schema.typedefs"

return {
    -- this plugin only results in one custom DAO, named `rbac_user_roles`:
    rbac_user_roles = {
        name = "rbac_user_roles", -- the actual table in the database
        endpoint_key = "user_id",
        primary_key = { "user_id" },
        cache_key = { "user_id" },
        generate_admin_api = true,
        admin_api_name = "user-roles",
        admin_api_nested_name = "user-role",
        fields = {
            { user_id = { type = "string", required = true, unique = true } },
            { roles = { type = "set", elements = { type = "string" }, required = true } },
            { comment = { type = "string", required = false } },
            {
                -- also interted by the DAO itself
                created_at = typedefs.auto_timestamp_s,
            },
        },
    },
}

```

When i access the admin url /user-roles/xx, I get the following error.

What did I miss anything? Sorry for my poor english.

> 2019/12/19 20:37:02 [error] 31#0: \*43 lua coroutine: runtime error: …local/share/lua/5.1/kong/db/strategies/postgres/init.lua:495: attempt to index local ‘statement’ (a nil value)  
> stack traceback:  
> coroutine 0:  
> …local/share/lua/5.1/kong/db/strategies/postgres/init.lua: in function ‘execute’  
> …local/share/lua/5.1/kong/db/strategies/postgres/init.lua:743: in function ‘select\_by\_field’  
> /usr/local/share/lua/5.1/kong/db/dao/init.lua:577: in function ‘select\_entity’  
> /usr/local/share/lua/5.1/kong/api/endpoints.lua:405: in function ‘fn’  
> /usr/local/share/lua/5.1/kong/api/api\_helpers.lua:257: in function \</usr/local/share/lua/5.1/kong/api/api\_helpers.lua:240\>  
> coroutine 1:  
> [C]: in function ‘resume’  
> /usr/local/share/lua/5.1/lapis/application.lua:397: in function ‘handler’  
> /usr/local/share/lua/5.1/lapis/application.lua:130: in function ‘resolve’  
> /usr/local/share/lua/5.1/lapis/application.lua:167: in function \</usr/local/share/lua/5.1/lapis/application.lua:165\>  
> [C]: in function ‘xpcall’  
> /usr/local/share/lua/5.1/lapis/application.lua:173: in function ‘dispatch’  
> /usr/local/share/lua/5.1/lapis/nginx.lua:230: in function ‘serve’  
> /usr/local/share/lua/5.1/kong/init.lua:1122: in function ‘admin\_content’  
> content\_by\_lua(nginx-kong.conf:189):2: in main chunk, client: xxxx, server: kong\_admin, request: “GET /user-roles/k HTTP/1.1”, host: “xxxx:8001”  
> 2019/12/19 20:37:02 [error] 31#0: \*43 [lua] api\_helpers.lua:422: handle\_error(): /usr/local/share/lua/5.1/lapis/application.lua:401: …local/share/lua/5.1/kong/db/strategies/postgres/init.lua:495: attempt to index local ‘statement’ (a nil value)
