Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/n8n data tables official/SCHEMA_DESIGN
Reference · n8n data tables official

SCHEMA_DESIGN

Part of n8n data tables official. Install the skill and your agent reads this page when it needs the depth.

Data Table schema design

Day-one schema decisions stick for the table's life. Data Tables are forgiving (add columns later) but constrained (no foreign keys, modest scale, n8n-internal, no in-place column type changes). Once a column is string, it stays string until you create a new column and migrate. Pick types deliberately on day one.

The system-managed columns

id          bigserial   primary key, auto-assigned, can't write to
createdAt   timestamp   set on insert
updatedAt   timestamp   refreshed on each update

Don't declare these in create_data_table. Build your schema as if they exist, because they do.

Picking column types

Primitives only:

Type When
string Text, IDs, enums, anything non-numeric/non-boolean
number Counters, prices, scores, anything you'll do math on
boolean True/false flags. Don't overload string with 'yes'/'no'.
date Timestamps you set explicitly (distinct from auto createdAt/updatedAt)

No JSON / object / array column types. Only the four primitives above.

The _object convention for nested data

When you need to store an object or array (e.g., the keyInsights array from an LLM, a parsed JSON response), use a string column and stringify on write. Mark the column with an _object postfix so future readers (humans and agents) know to parse it:

// On insert:
columns: {
    value: {
        arxivId: '={{ $json.arxivId }}',
        keyInsights_object: '={{ JSON.stringify($("Summarize").item.json.output.keyInsights) }}',
        topics_object: '={{ JSON.stringify($("Summarize").item.json.output.topics) }}',
    },
}

// On read:
{{ JSON.parse($("Get Paper").item.json.keyInsights_object) }}

The _object postfix is the contract: any column ending in _object holds a JSON-stringified value and must be JSON.parse(...)'d on read. Workflows reading the table know what to do without inspecting the data.

Storage format ≠ interface format

The most important rule about _object columns: stringify-on-write, parse-on-read, and never let the stringified shape leak past the storage boundary. The string is the storage format, not the interface format.

What this means in practice:

Why: the caller doesn't (and shouldn't) know that you store things as stringified strings. That's an internal implementation detail of the table-owning workflow. Forcing every caller to remember to JSON.parse is the same kind of API leak as exposing your DB schema directly to consumers.

The failure mode

Any sub-workflow that owns a Data Table with _object columns tends to develop two return paths: a "fresh" path (the data was just produced, still in natural shape) and a "cached" path (read back from the table, where _object fields are stringified). The wrong instinct: stringify the fresh path's output to "match" the cached shape. The right instinct: parse the cached path's output, so both paths return arrays as arrays and objects as objects.

Symptom of the wrong choice: every caller has to JSON.parse(...) the return values. Templates choke, downstream tools see strings where they expect arrays, and the whole system has a hidden coupling to your storage representation.

Fix: in the sub-workflow's final return node, parse any _object field back to its natural shape:

// Final return node (Set / Edit Fields):
{
    id:       '={{ $("Merge").item.json.id }}',
    name:     '={{ $("Merge").item.json.name }}',
    items:    '={{ JSON.parse($("Merge").item.json.items_object) }}',
    metadata: '={{ JSON.parse($("Merge").item.json.metadata_object) }}',
}

The return contract is: arrays as arrays, objects as objects. Storage representation stays inside the table-owning workflow.

When NOT to use _object columns

Naming

Designing relationally without foreign keys

Data Tables don't enforce referential integrity, and they don't run multi-row transactions. You're responsible for both: integrity via workflow logic, atomicity via error handling.

No transactions, plan for partial failure

If you Insert a parent then Insert a child and the child fails, the parent row is already written. There is no rollback. Any relational sequence that spans more than one write (parent + child Inserts, cascade-delete, multi-table updates) needs error handling, full stop. Pick one:

See n8n-error-handling-official for the error-output wiring.

Reference rows by id

Child holds parent's id:

Papers              Papers.id is the key
  id (auto)
  arxivId (string)
  title (string)
  ...

Paper Summaries     paperId references Papers.id
  id (auto)
  paperId (number)
  summaryText (string)
  generatedAt (date)

When inserting a child, capture the parent's id from a prior get (or the insert response):

// After an insert into Papers, the response has { id, createdAt, updatedAt }.
// Use that id directly:
{
    operation: 'insert',
    dataTableId: { ..., value: '<Paper Summaries table id>' },
    columns: {
        mappingMode: 'defineBelow',
        value: {
            paperId: '={{ $('Insert Paper').item.json.id }}',
            summaryText: '={{ $('Summarize').item.json.output.tldr }}',
            generatedAt: '={{ $now.toISO() }}',
        },
    },
}

Enforce integrity in the workflow

Before inserting a child, look up the parent. Before deleting a parent, decide:

Pick one per relationship. Mixed strategies cause silent bugs.

Watch for "child without parent"

Delete a parent and forget children, and they point at a non-existent id. n8n won't tell you. Symptoms surface later when joins return nothing.

Guards:

When Data Tables are the wrong tool

Reach for an external DB when:

When Data Tables ARE the right tool:

Schema evolution

A healthy table

Mapping mode on Insert/Update/Upsert

The columns parameter has two modes: mappingMode: 'defineBelow' (manual per-column expressions) and mappingMode: 'autoMapInputData' (n8n maps by upstream field name).

Default to defineBelow. Explicit, expressions sit at the consumer, refactors read clearly. Auto-map only when you have a stable 1:1 between upstream field names and column names. Drift in either side silently breaks the mapping.

For the $json.x vs $('Node Name').item.json.x discipline that prevents silent NULLs when intermediate nodes strip json, see n8n-expressions-official. For Merge convergence and same-shape branches, see n8n-node-configuration-official references/MERGE_NODE.md.

Cross-references

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.