drizzle-team/drizzle-orm · error · Error
${reason}. You can't specify "${fkTableName}" as parameter i
Error message
${reason}.
You can't specify "${fkTableName}" as parameter in ${table.name}.with object.
For more details, check this: https://orm.drizzle.team/docs/guides/seeding-using-with-option What it means
The refinements `.with` option lets you seed related rows: for table T you specify { with: { otherTable: ratioOrWeights } }. drizzle-seed validates that otherTable is a known dependant of T in the parsed relations. If otherTable has no reference back to T, or is a self-reference, or the one-to-many relation was not included in the schema passed to seed(), the `.with` entry is rejected.
Source
Thrown at drizzle-seed/src/services/SeedService.ts:116
tablesPossibleGenerators[i]!.count = refinements[table.name]!.count;
}
if (refinements[table.name]!.with !== undefined) {
tablesPossibleGenerators[i]!.count = refinements[table.name]!.count
|| options?.count
|| this.defaultCountForTable;
let idx: number;
for (
const fkTableName of Object.keys(
refinements[table.name]!.with as {},
)
) {
if (!tablesInOutRelations[table.name]?.dependantTableNames.has(fkTableName)) {
const reason = tablesInOutRelations[table.name]?.selfRelation === true
? `"${table.name}" table has self reference`
: `"${fkTableName}" table doesn't have a reference to "${table.name}" table or`
+ `\nyou didn't include your one-to-many relation in the seed function schema`;
throw new Error(
`${reason}.` + `\nYou can't specify "${fkTableName}" as parameter in ${table.name}.with object.`
+ `\n\nFor more details, check this: https://orm.drizzle.team/docs/guides/seeding-using-with-option`,
);
}
idx = tablesPossibleGenerators.findIndex(
(table) => table.tableName === fkTableName,
);
if (idx !== -1) {
let newTableWithCount: number,
weightedCountSeed: number | undefined;
if (
typeof refinements![table.name]!.with![fkTableName] === 'number'
) {
newTableWithCount = (tablesPossibleGenerators[i]!.withCount
|| tablesPossibleGenerators[i]!.count)!
* (refinements[table.name]!.with![fkTableName] as number);
} else {View on GitHub (pinned to b7862528fd)
Solutions
- Verify the table named in `.with` actually has a foreign key referencing the current table and that the relation is exported in the schema passed to seed().
- If it is a self-referential table, remove the `.with` entry for the self-reference and handle self-FK seeding via refinements on the column instead.
- Correct the direction: `.with` keys must be tables that depend on (FK into) the current table, not the reverse.
Example fix
// before — 'orders' has no FK back to 'users', or relation not in schema
refinements = { users: { with: { orders: 3 } } }
// after — ensure orders.userId FK exists and schema includes it
export const schema = { users, orders, ... };
await seed(db, { schema }, { count: 10 }); Defensive patterns
Strategy: validation
Validate before calling
// Before seeding, verify every table in a `.with` refinement has a FK back to the parent
// and that both tables are in the schema object.
function validateWithOption(
schema: Record<string, any>,
refinements: Record<string, any>,
getRelations: (schema: Record<string, any>) => Map<string, Set<string>>
): string[] {
const errors: string[] = [];
const dependants = getRelations(schema); // tableName -> Set of tables that FK into it
for (const [table, ref] of Object.entries(refinements)) {
if (!ref.with) continue;
for (const fkTable of Object.keys(ref.with)) {
if (!dependants.get(table)?.has(fkTable)) {
errors.push(`${table}.with references '${fkTable}' which is not a dependant. Check FK direction and schema inclusion.`);
}
}
}
return errors;
} Prevention
- Always pass the full set of related tables in the schema object to seed().
- Double-check FK direction: `.with` keys are tables that reference the parent, not tables the parent references.
- Keep refinements in sync with schema changes — remove stale `.with` entries after relation refactors.
When it happens
Trigger: Specifying refinements[T].with = { X: 2 } when table X does not foreign-key into T; using `.with` on a table that has a self-referential FK; or forgetting to export a relation in the schema object so drizzle-seed never sees the T<->X link.
Common situations: Schema refactor that removed or renamed a relation but left stale refinements; passing a partial schema to seed() that omits the related table; misunderstanding `.with` direction (it must follow the FK from the dependant side).
Related errors
- There is not enough information to infer relation "${sourceT
- Column '${col.name}' has not null contraint, and you didn't
- The '${table1.name}' and '${table2.name}' tables have not nu
- unsupported dialect
- unsupported relation type
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/c355e4d4ebb18046.json.
Report an issue: GitHub.