cube-js/cube · error · Error

You have to select at least one table

Error message

You have to select at least one table

What it means

The generate-schema endpoint requires a non-empty `tables` array in the request body naming the tables to generate schemas for. If req.body.tables is falsy, this Error is thrown after the body-parser check.

Source

Thrown at packages/cubejs-server-core/src/core/DevServer.ts:168

    app.get('/playground/files', catchErrors(async (req, res) => {
      this.cubejsServer.event('Dev Server Files Load');
      const files = await this.cubejsServer.repository.dataSchemaFiles();
      res.json({
        files: files.map(f => ({
          ...f,
          absPath: path.resolve(path.join(this.cubejsServer.repository.localPath(), f.fileName))
        }))
      });
    }));

    app.post('/playground/generate-schema', catchErrors(async (req, res) => {
      this.cubejsServer.event('Dev Server Generate Schema');
      if (!req.body) {
        throw new Error('Your express app config is missing body-parser middleware. Typical config can look like: `app.use(bodyParser.json({ limit: \'50mb\' }));`');
      }

      if (!req.body.tables) {
        throw new Error('You have to select at least one table');
      }

      const dataSource = req.body.dataSource || 'default';

      const driver = await this.cubejsServer.getDriver({
        dataSource,
        authInfo: null,
        securityContext: null,
        requestId: getRequestIdFromRequest(req),
      });
      const tablesSchema = req.body.tablesSchema || (await driver.tablesSchema());

      if (!Object.values(SchemaFormat).includes(req.body.format)) {
        throw new Error(`Unknown schema format. Must be one of ${Object.values(SchemaFormat)}`);
      }

      const scaffoldingTemplate = new ScaffoldingTemplate(tablesSchema, driver, {
        format: req.body.format,

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Include tables in the POST body, e.g. { tables: ['public.orders'], format: 'yaml', dataSource: 'default' }
  2. Fix the UI/client to always send the selected tables array
  3. Validate the payload client-side before calling the endpoint

Example fix

// before
await fetch('/cubejs-system/v1/playground/generate-schema', { body: JSON.stringify({ format: 'yaml' }) });
// after
await fetch('/cubejs-system/v1/playground/generate-schema', { body: JSON.stringify({ format: 'yaml', tables: ['public.orders'] }) });
Defensive patterns

Strategy: validation

Validate before calling

const body = { tables: selectedTables, format: 'yaml', dataSource: 'default' };
if (!Array.isArray(body.tables) || body.tables.length === 0) throw new Error('Select at least one table before generating schemas');

Type guard

const hasTables = (b: unknown): b is { tables: string[] } => typeof b === 'object' && b != null && Array.isArray((b as any).tables) && (b as any).tables.length > 0;

Try / catch

try { await generateSchema(body); } catch (e) { if (e.message === 'You have to select at least one table') { /* re-open table picker */ } else throw e; }

Prevention

When it happens

Trigger: POSTing to /playground/generate-schema without a `tables` field, with `tables: null`, or with an empty selection from the schema-builder UI.

Common situations: Custom tooling calling the playground API directly; UI state where the user didn't tick any tables; API contract changes between client and server versions.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/ebe6116e090fc058. Report an issue: GitHub.