luizotavio32 commented on code in PR #31303: URL: https://github.com/apache/superset/pull/31303#discussion_r1878684515
########## superset/migrations/shared/utils.py: ########## @@ -185,15 +193,211 @@ def has_table(table_name: str) -> bool: return table_exists -def add_column_if_not_exists(table_name: str, column: sa.Column) -> None: +def drop_fks_for_table(table_name: str) -> None: + """ + Drop all foreign key constraints for a table if it exist and the database + is not sqlite. + + :param table_name: The table name to drop foreign key constraints for + """ + connection = op.get_bind() + inspector = Inspector.from_engine(connection) + + if isinstance(connection.dialect, SQLiteDialect): + return # sqlite doesn't like constraints + + if has_table(table_name): + foreign_keys = inspector.get_foreign_keys(table_name) + + for fk in foreign_keys: Review Comment: Done  -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org