{"record":{"id":"802bcab76cc30abd","repo":"apache/superset","slug":"table-already-exists-you-can-change-your-if-tabl","errorCode":null,"errorMessage":"Table already exists. You can change your 'if table already exists' strategy to append or replace or provide a different Table Name to use.","messagePattern":"Table already exists\\. You can change your 'if table already exists' strategy to append or replace or provide a different Table Name to use\\.","errorType":"exception","errorClass":"DatabaseUploadFailed","httpStatus":422,"severity":"error","filePath":"superset/commands/database/uploaders/base.py","lineNumber":131,"sourceCode":"        try:\n            data_table = Table(table=table_name, schema=schema_name)\n            to_sql_kwargs = {\n                \"chunksize\": READ_CHUNK_SIZE,\n                \"if_exists\": self._options.get(\"already_exists\", \"fail\"),\n                \"index\": self._options.get(\"dataframe_index\", False),\n            }\n            if self._options.get(\"index_label\") and self._options.get(\n                \"dataframe_index\"\n            ):\n                to_sql_kwargs[\"index_label\"] = self._options.get(\"index_label\")\n            database.db_engine_spec.df_to_sql(\n                database,\n                data_table,\n                df,\n                to_sql_kwargs=to_sql_kwargs,\n            )\n        except ValueError as ex:\n            raise DatabaseUploadFailed(\n                message=_(\n                    \"Table already exists. You can change your \"\n                    \"'if table already exists' strategy to append or \"\n                    \"replace or provide a different Table Name to use.\"\n                )\n            ) from ex\n        except Exception as ex:\n            message = ex.message if hasattr(ex, \"message\") and ex.message else str(ex)\n            raise DatabaseUploadFailed(message=message, exception=ex) from ex\n\n\nclass UploadCommand(BaseCommand):\n    def __init__(  # pylint: disable=too-many-arguments\n        self,\n        model_id: int,\n        table_name: str,\n        file: Any,\n        schema: Optional[str],","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/uploaders/base.py#L113-L149","documentation":"DatabaseUploadFailed with the 'Table already exists' message is raised in BaseUploader when df_to_sql raises ValueError. It means the target table exists and the chosen 'if table already exists' strategy (mapped to pandas if_exists='fail') refuses to overwrite it.","triggerScenarios":"CSV/Excel upload to a table name that already exists in the schema while the strategy is set to 'fail' (the default append/replace not selected).","commonSituations":"Re-uploading the same file twice; uploading to a shared schema where a table with that name was created by someone else.","solutions":["Change the 'if table already exists' strategy to append or replace in the upload dialog","Or provide a different Table Name in the upload form","Drop/rename the existing table if a fresh load is intended"],"exampleFix":"// before\n options = {\"if_exists\": \"fail\"}\n\n// after\n options = {\"if_exists\": \"append\"}  # or \"replace\"","handlingStrategy":"validation","validationCode":"from sqlalchemy import inspect\n\nwith db_conn.get_sqla_engine() as engine:\n    exists = inspect(engine).has_table(table_name, schema=schema)\nif exists and strategy == \"fail\":\n    raise ValueError(\"choose append/replace or a new table name\")","typeGuard":null,"tryCatchPattern":"try:\n    UploadCommand(...).run()\nexcept DatabaseUploadFailed as e:\n    if \"already exists\" in str(e):\n        # surface strategy choice to the user\n        ...","preventionTips":["Pre-check table existence before upload","Default the dialog to append/replace for repeat loads"],"tags":["database","upload","csv","conflict"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}