-- Method 1: Check the table structure to see if UNIQUE is in column definition
SHOW CREATE TABLE `referrals`;

-- Look for: `referralCode` VARCHAR(50) NOT NULL UNIQUE
-- If you see UNIQUE in the column definition, use Method 2 below

-- Method 2: Check all constraints on referralCode column
SELECT 
    CONSTRAINT_NAME,
    CONSTRAINT_TYPE,
    COLUMN_NAME,
    TABLE_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'referrals'
AND COLUMN_NAME = 'referralCode';

-- Method 3: Check all indexes (including unique ones)
SELECT 
    INDEX_NAME,
    NON_UNIQUE,
    COLUMN_NAME,
    SEQ_IN_INDEX
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'referrals'
AND COLUMN_NAME = 'referralCode';

-- If UNIQUE is in the column definition, use this:
-- ALTER TABLE `referrals` MODIFY COLUMN `referralCode` VARCHAR(50) NOT NULL;

-- Then create non-unique index:
-- CREATE INDEX `idx_referral_code` ON `referrals`(`referralCode`);

