{"record":{"id":"5c4f638b771b5e16","repo":"sqlalchemy/alembic","slug":"the-s-method-does-not-apply-to-a-batch-table-alte","errorCode":null,"errorMessage":"The %s method does not apply to a batch table alter operation.","messagePattern":"The (.+?) method does not apply to a batch table alter operation\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"alembic/operations/base.py","lineNumber":1713,"sourceCode":"\n    This basically omits the ``table_name`` and ``schema`` parameters\n    from associated methods, as these are a given when running under batch\n    mode.\n\n    .. seealso::\n\n        :meth:`.Operations.batch_alter_table`\n\n    Note that as of 0.8, most of the methods on this class are produced\n    dynamically using the :meth:`.Operations.register_operation`\n    method.\n\n    \"\"\"\n\n    impl: BatchOperationsImpl\n\n    def _noop(self, operation: Any) -> NoReturn:\n        raise NotImplementedError(\n            \"The %s method does not apply to a batch table alter operation.\"\n            % operation\n        )\n\n    if TYPE_CHECKING:\n        # START STUB FUNCTIONS: batch_op\n        # ### the following stubs are generated by tools/write_pyi.py ###\n        # ### do not edit ###\n\n        def add_column(\n            self,\n            column: Column[Any],\n            *,\n            insert_before: str | None = None,\n            insert_after: str | None = None,\n            if_not_exists: bool | None = None,\n            inline_references: bool | None = None,\n            inline_primary_key: bool | None = None,","sourceCodeStart":1695,"sourceCodeEnd":1731,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/5551b5d35f985c99cb8f1af2b3c526b050e4c059/alembic/operations/base.py#L1695-L1731","documentation":"BatchOperations._noop raises NotImplementedError when a top-level Operations method that is meaningless inside batch mode is invoked on the batch operations proxy. Inside a `with op.batch_alter_table('t') as batch_op:` block, only column/constraint/index operations that pertain to the table being altered are valid; operations like create_table, drop_table, create_index at the top level are routed to _noop.","triggerScenarios":"Calling batch_op.create_table(...), batch_op.drop_table(...), or another operation wired to _noop inside a batch_alter_table block. Also triggered by methods that only apply to whole-database context, not a single batched table.","commonSituations":"Copy-pasting top-level op.create_table(...) into a batch block and forgetting to replace op with the non-batch Operations; attempting to create an index on a different table inside a batch context.","solutions":["Move the unsupported operation outside the batch_alter_table block and use the top-level op object.","Verify you are calling batch_op methods that apply to the table being batched (add_column, alter_column, drop_column, create/drop_constraint, create/drop_index).","For create_table/drop_table, use the non-batch op.create_table outside the with block."],"exampleFix":"# before (wrong)\nwith op.batch_alter_table('t') as batch_op:\n    batch_op.create_table('new_t', ...)  # _noop error\n\n# after\nwith op.batch_alter_table('t') as batch_op:\n    batch_op.alter_column('c', type_=sa.String(50))\nop.create_table('new_t', ...)  # outside batch","handlingStrategy":"type-guard","validationCode":"BATCH_ALLOWED = {'add_column','drop_column','alter_column',\n              'create_constraint','drop_constraint',\n              'create_index','drop_index',\n              'create_table_comment','drop_table_comment',\n              'create_column_comment'}\n\ndef batch_call(batch_op, method, *a, **k):\n    if method not in BATCH_ALLOWED:\n        raise ValueError(f'{method} is not valid inside batch_alter_table')\n    getattr(batch_op, method)(*a, **k)","typeGuard":"def is_batch_safe_method(name: str) -> bool:\n    return name in {'add_column','drop_column','alter_column',\n                    'create_constraint','drop_constraint',\n                    'create_index','drop_index',\n                    'create_table_comment','drop_table_comment',\n                    'create_column_comment'}","tryCatchPattern":null,"preventionTips":["Only call table-modifying methods on batch_op inside a batch block.","Use the top-level op object for create_table/drop_table and whole-DB operations.","Review batch blocks to ensure no stray top-level operations were pasted in."],"tags":["batch-mode","operations","not-supported","ddl"],"backgroundTag":null,"analyzedSha":"5551b5d35f985c99cb8f1af2b3c526b050e4c059","analyzedAt":"2026-08-11T01:38:46.612Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}