-- Detach qt_configurations from qt_users (ownership is owner_username text) -- Safe for MySQL 8+/MariaDB 10.2+ via INFORMATION_SCHEMA checks. SET @fk_exists := ( SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = 'qt_configurations' AND CONSTRAINT_NAME = 'fk_qt_configurations_user' AND CONSTRAINT_TYPE = 'FOREIGN KEY' ); SET @drop_fk_sql := IF( @fk_exists > 0, 'ALTER TABLE qt_configurations DROP FOREIGN KEY fk_qt_configurations_user', 'SELECT ''fk_qt_configurations_user not found, skip'' ' ); PREPARE stmt_drop_fk FROM @drop_fk_sql; EXECUTE stmt_drop_fk; DEALLOCATE PREPARE stmt_drop_fk; -- user_id becomes optional legacy column (can stay NULL) ALTER TABLE qt_configurations MODIFY COLUMN user_id BIGINT UNSIGNED NULL;