{"id":"6314ce04c96fde9f","repo":"sequelize/sequelize","slug":"model-model-name-has-already-been-initialized","errorCode":null,"errorMessage":"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","messagePattern":"Model (.+?) 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","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/model-definition.ts","lineNumber":868,"sourceCode":"\n  isParanoid(): boolean {\n    return Boolean(this.timestampAttributeNames.deletedAt);\n  }\n}\n\nconst modelDefinitionListeners = new Set<(model: ModelStatic) => void>();\nexport function listenForModelDefinition(callback: (model: ModelStatic) => void): void {\n  modelDefinitionListeners.add(callback);\n}\n\nconst modelDefinitions = new WeakMap</* model class */ Function, ModelDefinition<any>>();\n\nexport function registerModelDefinition<M extends Model>(\n  model: ModelStatic<M>,\n  modelDefinition: ModelDefinition<M>,\n): void {\n  if (modelDefinitions.has(model)) {\n    throw new Error(\n      `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`,\n    );\n  }\n\n  modelDefinitions.set(model, modelDefinition);\n\n  for (const listener of modelDefinitionListeners) {\n    listener(model);\n  }\n}\n\nexport function removeModelDefinition(model: ModelStatic): void {\n  modelDefinitions.delete(model);\n}\n\nexport function hasModelDefinition(model: ModelStatic): boolean {\n  return modelDefinitions.has(model);\n}","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/model-definition.ts#L850-L886","documentation":"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.","triggerScenarios":"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.","commonSituations":"Multi-tenant setups that create multiple Sequelize instances; test suites that reuse imported models across connections; Jest/Vite HMR re-running module initialization.","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."],"exampleFix":"// before\nUser.init(attrs, { sequelize: instanceA });\nUser.init(attrs, { sequelize: instanceB }); // throws\n// after\nconst UserA = class extends Model {};\nconst UserB = class extends Model {};\nUserA.init(attrs, { sequelize: instanceA });\nUserB.init(attrs, { sequelize: instanceB });","handlingStrategy":"validation","validationCode":"import { hasModelDefinition, removeModelDefinition } from '@sequelize/core';\nfunction safeInit(Model, attrs, opts) {\n  if (hasModelDefinition(Model)) {\n    throw new Error(`${Model.name} already bound; create a subclass for a new instance`);\n  }\n  Model.init(attrs, opts);\n}","typeGuard":"import { hasModelDefinition } from '@sequelize/core';\nfunction isModelBound(Model): boolean { return hasModelDefinition(Model); }","tryCatchPattern":null,"preventionTips":["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."],"tags":["model-definition","init","multi-instance","hmr"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}