-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot create table with same name from a different datasource #3829
Comments
Feel free to open a PR |
Will do |
I think this open PR solves this: #3583 |
|
https://github.com/apache/incubator-superset/compare/master...frankfarrell:tables-constraints?expand=1 |
Root cause here is that the alembic migrations scripts first creates a unique constraint on table name: However, sqlite doesn't allow dropping unnamed unique constraints: Solution would be to rename table, create new table and copy over data in a new migration. Or use some other db :) |
We could also alter the creation of the constraint in the first place. Won't help existing installations but it will help future ones. |
@mistercrunch That's also an option, I wasn't sure if you wanted to keep the migration scripts immutable or not. Chances are that nobody will upgrade an sqlite db in place. |
In general we want to keep the migrations static but in cases like this I think it's ok to alter them, as long as downstream migration account for both branches in history. I'll let @john-bodley review the PR since he's done something very similar on the Druid side recently. |
@frankfarrell are you certain you weren't able to delete an unnamed uniqueness constraint for SQLite? There's a section on the Alembic documentation about dealing with constraints in SQLite. I was able to leverage this logic for dropping uniqueness constraints here |
@john-bodley I am not certain no. I can try that tomorrow, thanks for the info! These 2 following constraint modifications didn't work : |
I'm having the same issue. Is this still being worked on? |
I created this PR #3885 which solves the issue. Its uses plain SQL, I haven't updated it to use alembic as described by @john-bodley above. Should I do that or does it look ok to merge as is? |
Any news by chance ? |
Oh, just tested 0.24.0 and seem it's working, so maybe someone should close this issue? |
I am using 0.25.6 . This still seems to be an issue. |
I was thinking, since users generally don't migrate once the app is initialised, how about we add the script to re configure the |
@SanjayJosh it might be worth opening a new issue, this may be a regression. |
@SanjayJosh It seems there's no new issue about the regression? Or did you just found it's gone? |
I just can'( believe it's not possible to have two databases with tables having the same name??!! |
This problem might be sqlite specific because of the very peculiar way of working with alembic. |
@mistercrunch: Can this be reopend? It still isn't fixed. I also experience this issue. |
Yes it works in combination with modifing this line in SqlaTable class
`__table_args__ = ( UniqueConstraint("database_id", "schema", "table_name"),)`
|
I found that this problem still exists when using mysql, because the "table_name" unique index created in the "tables" table only contains "table_name" but not "database_id", and after adding "database_id" to the unique index, the table can be created normally. |
I just hit the same issue, with the default sqlite metadata source. Fixed it in sqlite3 with
Seems like it isn't fixed in the latest stable version, which just needs
|
Still seeing the same issue in 1.0.0 |
but,the unique only
as the code say, it show be |
Make sure these boxes are checked before submitting your issue - thank you!
Superset version
0.19.1
Expected results
That you could add the same table from a differnet datasource
Actual results
(raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (sqlite3.IntegrityError) UNIQUE constraint failed: tables.table_name [SQL: 'INSERT INTO tables (created_on, changed_on, description, default_endpoint, is_featured, filter_select_enabled, "offset", cache_timeout, params, perm, table_name, main_dttm_col, database_id, fetch_values_predicate, user_id, schema, sql, created_by_fk, changed_by_fk) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('2017-11-10 16:36:45.635385', '2017-11-10 16:36:45.635417', None, None, 0, 0, 0, None, None, None, '<table_name>', None, 2, None, None, '', None, None, None)]
Steps to reproduce
We have a few datasources using the same schema. We would like to configure query tables from each.
It seems an easy fix would be just to change this line: https://github.com/apache/incubator-
superset/blob/master/superset/migrations/versions/4e6a06bad7a8_init.py#L84
to
sa.UniqueConstraint('table_name', 'database_id')
. This line does have such a constraint ( with schema too), https://github.com/apache/incubator-superset/blob/1ea4521d0c116d96b51749613347279669529dd0/superset/connectors/sqla/models.py#L188Its similar to https://github.com/apache/incubator-superset/pull/3583/files, so perhaps a fix could be included in that PR too?
Thanks, great project by the way!
The text was updated successfully, but these errors were encountered: