sequelize/sequelize · error · Error
Model ${model.name} has already been initialized. Models can
Error message
Model ${model.name} has already been initialized. Models can only belong to one Sequelize instance. Registering the same model with multiple Sequelize instances is not yet supported. Please see https://github.com/sequelize/sequelize/issues/15389 What it means
Thrown by registerModelDefinition when a Model class already has an associated ModelDefinition (model-definition.ts:867). Sequelize ties a Model class to a single Sequelize instance via a WeakMap; re-initializing the same class on another instance (or re-calling init on the same class) is rejected because the prior binding still exists.
Source
Thrown at packages/core/src/model-definition.ts:868
isParanoid(): boolean {
return Boolean(this.timestampAttributeNames.deletedAt);
}
}
const modelDefinitionListeners = new Set<(model: ModelStatic) => void>();
export function listenForModelDefinition(callback: (model: ModelStatic) => void): void {
modelDefinitionListeners.add(callback);
}
const modelDefinitions = new WeakMap</* model class */ Function, ModelDefinition<any>>();
export function registerModelDefinition<M extends Model>(
model: ModelStatic<M>,
modelDefinition: ModelDefinition<M>,
): void {
if (modelDefinitions.has(model)) {
throw new Error(
`Model ${model.name} has already been initialized. Models can only belong to one Sequelize instance. Registering the same model with multiple Sequelize instances is not yet supported. Please see https://github.com/sequelize/sequelize/issues/15389`,
);
}
modelDefinitions.set(model, modelDefinition);
for (const listener of modelDefinitionListeners) {
listener(model);
}
}
export function removeModelDefinition(model: ModelStatic): void {
modelDefinitions.delete(model);
}
export function hasModelDefinition(model: ModelStatic): boolean {
return modelDefinitions.has(model);
}View on GitHub (pinned to 7e1deec499)
Solutions
- Define the Model on only one Sequelize instance; for multi-tenant, create separate Model subclasses per instance.
- Call removeModelDefinition(model) (or model.sequelize = null pattern) before re-initializing when intentionally rebinding.
- In HMR/dev setups, isolate model definitions per reload or reset module registry between reloads.
Example fix
// before
User.init(attrs, { sequelize: instanceA });
User.init(attrs, { sequelize: instanceB }); // throws
// after
const UserA = class extends Model {};
const UserB = class extends Model {};
UserA.init(attrs, { sequelize: instanceA });
UserB.init(attrs, { sequelize: instanceB }); Defensive patterns
Strategy: validation
Validate before calling
import { hasModelDefinition, removeModelDefinition } from '@sequelize/core';
function safeInit(Model, attrs, opts) {
if (hasModelDefinition(Model)) {
throw new Error(`${Model.name} already bound; create a subclass for a new instance`);
}
Model.init(attrs, opts);
} Type guard
import { hasModelDefinition } from '@sequelize/core';
function isModelBound(Model): boolean { return hasModelDefinition(Model); } Prevention
- Create distinct Model subclasses per Sequelize instance in multi-tenant apps.
- In HMR/dev, clear the module cache or call removeModelDefinition before re-init.
- Avoid calling Model.init twice on the same class.
When it happens
Trigger: Calling User.init(...) twice; sharing a Model class file across two Sequelize instances in the same process; hot-reloading (HMR) in dev servers that re-evaluates the model module while the old class object is retained.
Common situations: Multi-tenant setups that create multiple Sequelize instances; test suites that reuse imported models across connections; Jest/Vite HMR re-running module initialization.
Related errors
- Attribute "${this.modelName}.${attributeName}" must be speci
- Attribute "${this.modelName}.${attributeName}" does not spec
- Model ${model.name} has not been initialized yet.
- Expected type to be a string, a DataType class, or a DataTyp
- This DataType is already attached to ${printContext(this.usa
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/6314ce04c96fde9f.json.
Report an issue: GitHub.