{"id":"c7eb8d04d80548da","repo":"drizzle-team/drizzle-orm","slug":"no-fields-selected-for-table-tableconfig-tsname-c7eb8d","errorCode":null,"errorMessage":"No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\"). You need to have at least one item in \"columns\", \"with\" or \"extras\". If you need to select all columns, omit the \"columns\" key or set it to undefined.","messagePattern":"No fields selected for table \"(.+?)\" \\(\"(.+?)\"\\)\\. You need to have at least one item in \"columns\", \"with\" or \"extras\"\\. If you need to select all columns, omit the \"columns\" key or set it to undefined\\.","errorType":"validation","errorClass":"DrizzleError","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/sqlite-core/dialect.ts","lineNumber":827,"sourceCode":"\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = sql`(${builtRelation.sql})`.as(selectedRelationTsKey);\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage:\n\t\t\t\t\t`No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\"). You need to have at least one item in \"columns\", \"with\" or \"extras\". If you need to select all columns, omit the \"columns\" key or set it to undefined.`,\n\t\t\t});\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`json_array(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field }) =>\n\t\t\t\t\t\tis(field, SQLiteColumn)\n\t\t\t\t\t\t\t? sql.identifier(this.casing.getColumnCasing(field))\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sqlite-core/dialect.ts#L809-L845","documentation":"Thrown while building a nested relational (with/relations) selection (dialect.ts:827) when a table's config object has empty columns, with, AND extras — i.e. nothing to select for that table. Drizzle needs at least one selected item per table in a relational query; an all-empty config is treated as a user error. To select every column you should omit the columns key (or set it to undefined) rather than pass an empty object.","triggerScenarios":"Calling a nested relation with { columns: {} } (explicit empty object) and no with/extras; passing a config where columns was set to {} by a transform that removed all keys. Setting columns to undefined (select-all) does NOT throw — only an explicit empty object does.","commonSituations":"Programmatically building a 'columns to select' object from a whitelist that came back empty; copy-pasting a relational query and deleting the columns key contents; a serializer that strips keys and leaves {}.","solutions":["If you want all columns: omit the columns key entirely (or set columns: undefined).","If selecting a subset: ensure at least one column key is set to true.","Add a with or extras entry if you intentionally select no base columns but want relation/extra fields."],"exampleFix":"// before\nawait db.query.users.findMany({\n  with: { posts: { columns: {} } }, // empty object -> throws\n});\n\n// after — select all post columns\nawait db.query.users.findMany({\n  with: { posts: true },\n});\n// or a subset\nawait db.query.users.findMany({\n  with: { posts: { columns: { id: true, title: true } } },\n});","handlingStrategy":"validation","validationCode":"function normaliseColumns(config) {\n  // treat {} as 'select all'\n  if (config && 'columns' in config && config.columns !== undefined\n      && Object.keys(config.columns).length === 0) {\n    const { columns, ...rest } = config;\n    return { ...rest, columns: undefined };\n  }\n  return config;\n}","typeGuard":"const hasSelectableFields = (cfg) =>\n  (cfg.columns && Object.keys(cfg.columns).length > 0)\n  || (cfg.with && Object.keys(cfg.with).length > 0)\n  || (cfg.extras && Object.keys(cfg.extras).length > 0);","tryCatchPattern":null,"preventionTips":["Use true (select-all) instead of an empty columns object.","When building columns from a whitelist, default to undefined when the whitelist is empty.","Document that columns:{} is an error, not select-all."],"tags":["relational-query","select","nested","query-builder"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}