UPDATE user_settings SET journal_id = 0 WHERE journal_id IS NULL ALTER TABLE user_settings CHANGE COLUMN journal_id journal_id BIGINT NOT NULL DEFAULT 0 ALTER TABLE user_settings DROP INDEX user_settings_pkey, ADD INDEX user_settings_pkey (user_id, locale, setting_name, journal_id) UPDATE user_settings SET journal_id = 0 WHERE journal_id IS NULL ALTER TABLE user_settings ALTER COLUMN journal_id SET NOT NULL ALTER TABLE user_settings ALTER COLUMN journal_id SET DEFAULT 0 DROP INDEX user_settings_pkey CREATE UNIQUE INDEX user_settings_pkey ON user_settings (user_id, locale, setting_name, journal_id)