dosubot[bot] commented on issue #37399: URL: https://github.com/apache/superset/issues/37399#issuecomment-3791178761
<!-- Greeting --> Hi @applesauce49! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team. <!-- Answer --> Superset's CSV import relies on pandas' DataFrame.to_sql, which does not add a PRIMARY KEY to the created table. When MySQL's sql_require_primary_key is ON, this causes the import to fail because the generated CREATE TABLE statement lacks a PRIMARY KEY—even if an "index" column is present, it's not set as PRIMARY KEY. There is currently no built-in way in Superset to declare a PRIMARY KEY during CSV upload, and no configuration option to change this behavior. A practical workaround is to pre-create the target table in MySQL with a PRIMARY KEY before uploading your CSV, then use the "append" option during import. Alternatively, you could request a feature for primary key support in future releases, but as of now, this is a known limitation of the CSV upload flow in Superset and pandas. References: - [Superset CSV upload code path](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/commands/database/uploaders/base.py#L70-L192) - [Superset database engine spec and pandas integration](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/db_engine_specs/base.py#L1151-L1778) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/291b86da-59f8-48c0-a57f-d8f3b4af7e3e?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github) [](https://cursor.com/link/prompt?text=Superset%27s%20CSV%20import%20relies%20on%20pandas%27%20DataFrame.to_sql%2C%20which%20does%20not%20add%20a%20PRIMARY%20KEY%20to%20the%20created%20table.%20When%20MySQL%27s%20sql_require_primary_key%20is%20ON%2C%20this%20causes%20the%20import%20to%20fail%20because%20the%20generated%20CREATE%20TABLE%20statement%20lacks%20a%20PRIMARY%20KEY%E2%80%94even%20if%20an%20%22index%22%20column%20is%20present%2C%20it%27s%20not%20set%20as%20PRIMARY%20KEY.%20There%20is%20currently%20no%20built-in%20way%20in%20Superset%20to%20declare%20a%20PRIMARY%20KEY%20during%20CSV%20upload%2C%20and%20no%20configuration%20option%20to%20change%20this%20behavior.%20%0A%0AA%20practical%20workaround%20is%20to%20pre-create%20the%20target%20table%20in%20MySQL%20with%20a%20PRIMARY%20K EY%20before%20uploading%20your%20CSV%2C%20then%20use%20the%20%22append%22%20option%20during%20import.%20Alternatively%2C%20you%20could%20request%20a%20feature%20for%20primary%20key%20support%20in%20future%20releases%2C%20but%20as%20of%20now%2C%20this%20is%20a%20known%20limitation%20of%20the%20CSV%20upload%20flow%20in%20Superset%20and%20pandas.%20%0A%0AReferences%3A%20%20%0A-%20%5BSuperset%20CSV%20upload%20code%20path%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/commands/database/uploaders/base.py%23L70-L192%29%20%20%0A-%20%5BSuperset%20database%20engine%20spec%20and%20pandas%20integration%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/db_engine_specs/base.py%23L1151-L1778%29) [](https://go.dosu.dev/discord-bot) [](https://twi tter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/37399) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
