apache / apache/superset

Unable to import CSV into hosted database that enforces primary key ID

Open
#37,399 4 comments 0 reactions 0 assignees View on GitHub
data:connect:mysql validation:required
Dominant language
Python
Stars
74.8k
Forks
18.3k
Avg merge
2d 5h
Merged PRs (30d)
685

Description

### Bug description

1. create a mysql connection to a mySQL hosted mysql server that enforces sql_require_primary_key = ON
2. Enable CSV importing on the mysql server connection.
3. Go through the Upload a file to database form and select any database on the server.

Result:
ERROR: (MySQLdb.OperationalError) (3750, "Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.")

here's the output of the table create command it's trying to do: [SQL: CREATE TABLE superset_storage.stripe_subscription_data ( "index" BIGINT,

You can see it's trying to add an index column, it's just not adding "PRIMARY KEY" to it.

### Screenshots/recordings

_No response_

### Superset version

6.0.0

### Python version

3.9

### Node version

16

### Browser

Safari

### Additional context

_No response_

### Checklist

- [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Contributor guide

Open the contributing guide

Research direction

Start with the CSV import flow and the generated CREATE TABLE statement shown in the report. Reproduce the upload against a MySQL server with sql_require_primary_key enabled, then trace where the generated index column is defined. Done means the CSV import succeeds without requiring the database setting to be disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.