Help needed when creating collection from nodejs into main data source

I’m struggling when creating collections from my nodejs code, they are created in the database, but do no appear within the main data source. Following the example here https://docs.nocobase.com/api/database is more than enough to get the table created, since it’s based off of sequelize I followed the normal pattern I use for sequelize.

I connected pgAdmin to the internal database so I could verify. The table is created upon initial run, the data is written into the table. The table just won’t display in the main data source. I can use the http api to do this, but this is far easier to do systematically.

import { Database } from ‘@nocobase/database’

// PostgreSQL database configuration parameters
export default const database = new Database({
dialect: ‘postgres’,
database: ‘database’,
username: ‘username’,
password: ‘password’,
host: ‘localhost’,
port: ‘port’
})

Model file:
import { database } from ‘database connection example above’
const UserCollection = database.collection({
name: ‘users’,
fields: [
{
name: ‘name’,
type: ‘string’,
},
{
name: ‘age’,
type: ‘integer’,
},
],
});

await UserCollection.sync() I’ve also used database.sync() here

export default UserCollection

Example in use
import { UserCollection } from ‘example above’

const UserRepository = UserCollection.repository();

await UserRepository.create({
name: ‘Mark’,
age: 18,
});

const create = await UserCollection.create({

Although the table is created in the database, it is not registered as a collection within NocoBase, and therefore will not appear in the main data source or UI.

To make it manageable in NocoBase, you need to define the collection and its fields using NocoBase’s db.collection() API.

Please refer to this section for details on how to define data structure:
https://docs.nocobase.com/api/database#define-data-structure

shleyZ,
Maybe I’m misunderstanding something, what you’re talking about is the equivalent to defining the model in sequelize. If you review my original post the section that says “Model File” does this. The link you sent me is even the example code I used to write out my initial question. What am I not understanding?

You’re right — db.sync() creates the table in the database.

But to make it appear in the NocoBase UI, you also need to register it in the internal metadata system:

const repo = database.getRepository<any>('collections');
if (repo) {
  await repo.db2cm('your_table_name');
}

This step tells NocoBase to display and manage the table in the admin panel.

Sorry shleyZ, not sure what I’m missing, but I haven’t been able to make this work through any amount of effort. I’ve dialed back to using the API to create the tables

I figured out the discrepancy, we were talking about two different things. I was writing jn my nodejs server and you were instructing me on the internals.

Hello!
How did you connect PgAdmin to internal database, because I couldn’t accomplish it. I used basic env :
PATH=–
HOSTNAME=eff29ee81785
POSTGRES_DB=nocobase
POSTGRES_PASSWORD=nocobase
POSTGRES_USER=nocobase
GOSU_VERSION=1.19
LANG=en_US.utf8
PG_MAJOR=16
PG_VERSION=16.11-1.pgdg13+1
PGDATA=/var/lib/postgresql/data
HOME=/root

and anyway no results at all

How did you setup the database when you deployed" Is it a postgres container?

Hello!
Thanks for the answer, yes it is

but its not actual anymore.

Hi, any update, Hi.

I’m experiencing the same issue in v1.9.47: newly created field collections do not appear in the UI. When I try to recreate them, I get error Field Name already exists

2026-05-10 13:38:37 [error] Field name "Fecha1_TM_Esquema" already exists in collection "ordenDeProduccion" extra={"method":"error-handler","err":"FieldNameExistsError: Field name \"Fecha1_TM_Esquema\" already exists in collection \"ordenDeProduccion\"\n  at _AsyncEmitter.<anonymous> (/home/automatizacion/nocobasetmb/node_modules/@nocobase/plugin-data-source-main/dist/server/server.js:216:15)\n  at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n  at async _AsyncEmitter.emitAsync (/home/automatizacion/nocobasetmb/node_modules/

This is hoy I see collection in UI, and fields are’nt showing