{"id":"9c89bf6b4f98dc28","repo":"sequelize/sequelize","slug":"attribute-attributename-on-model-model-name","errorCode":null,"errorMessage":"Attribute ${attributeName} on model ${model.name} cannot have both 'insertBefore' and 'insertAfter' set to true.","messagePattern":"Attribute (.+?) on model (.+?) cannot have both 'insertBefore' and 'insertAfter' set to true\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/decorators/shared/model.ts","lineNumber":217,"sourceCode":"\n  return modelOptions;\n}\n\nfunction getRegisteredAttributeOptions(model: ModelStatic): RegisteredAttributeOptions {\n  const descendantAttributes: RegisteredAttributeOptions = {\n    ...(registeredOptions.get(model)?.attributes ?? EMPTY_OBJECT),\n  };\n  const insertAfterAttributes: RegisteredAttributeOptions = {};\n  const insertBeforeAttributes: RegisteredAttributeOptions = {};\n\n  const parentModel = Object.getPrototypeOf(model);\n  if (isModelStatic(parentModel)) {\n    const parentAttributes: RegisteredAttributeOptions = getRegisteredAttributeOptions(parentModel);\n\n    for (const attributeName of Object.keys(parentAttributes)) {\n      const parentAttribute = { ...parentAttributes[attributeName] };\n      if (parentAttribute.insertBefore && parentAttribute.insertAfter) {\n        throw new Error(\n          `Attribute ${attributeName} on model ${model.name} cannot have both 'insertBefore' and 'insertAfter' set to true.`,\n        );\n      }\n\n      if (parentAttribute.type) {\n        if (typeof parentAttribute.type === 'function') {\n          parentAttribute.type = new parentAttribute.type();\n        } else {\n          parentAttribute.type = cloneDataType(parentAttribute.type);\n        }\n      }\n\n      // options that must be cloned\n      parentAttribute.unique = cloneDeep(parentAttribute.unique);\n      parentAttribute.index = cloneDeep(parentAttribute.index);\n      parentAttribute.references = cloneDeep(parentAttribute.references);\n      parentAttribute.validate = cloneDeep(parentAttribute.validate);\n","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/decorators/shared/model.ts#L199-L235","documentation":"Thrown while computing registered attribute options for a child model when an inherited parent attribute has both `insertBefore: true` and `insertAfter: true`. These flags control column ordering relative to other inherited columns; setting both is contradictory and the attribute-ordering algorithm cannot decide where to place the column, so it refuses.","triggerScenarios":"On an abstract/parent model, decorating an attribute with both @Before (or the insertBefore option) and @After (or insertAfter). The error surfaces when a concrete child class initializes and inherits that parent attribute, because ordering is computed at child-init time.","commonSituations":"Trying to force a column to appear in two positions. Copying decorator stacks from another column and not noticing the conflicting ordering decorators. Misunderstanding the insertBefore/insertAfter semantics as additive.","solutions":["Choose a single positioning strategy for the parent attribute: either insertBefore or insertAfter, not both.","If the column ordering requirement genuinely needs both, restructure the model so the column is defined once in the desired position.","Audit the parent/abstract model's attribute decorators for the flagged attribute name and remove one of the two ordering options."],"exampleFix":"// before\nabstract class Base extends Model {\n  @Attribute({ type: DataTypes.STRING, insertBefore: true, insertAfter: true })\n  status: string;\n}\n\n// after\nabstract class Base extends Model {\n  @Attribute({ type: DataTypes.STRING, insertBefore: true })\n  status: string;\n}","handlingStrategy":"validation","validationCode":"// Ensure no attribute has both insertBefore and insertAfter.\nfunction assertExclusivePositioning(attr: { insertBefore?: boolean; insertAfter?: boolean }) {\n  if (attr.insertBefore && attr.insertAfter) {\n    throw new Error('Attribute cannot have both insertBefore and insertAfter');\n  }\n}\nassertExclusivePositioning(baseAttr);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one column-positioning strategy per inherited attribute.","Audit abstract/base model attribute decorators for both flags.","Treat insertBefore/insertAfter as mutually exclusive in code review."],"tags":["decorators","attributes","column-ordering","inheritance"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}