USE dating_app; -- Replace the named CHECK in one ALTER when the server enforces it. -- MySQL 5.7 accepts but does not enforce CHECK constraints. SET @direction_check_exists = ( SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = 'swipes' AND CONSTRAINT_NAME = 'ck_swipe_direction' AND CONSTRAINT_TYPE = 'CHECK' ); SET @statement = IF( @direction_check_exists > 0, 'ALTER TABLE swipes DROP CHECK ck_swipe_direction, ADD CONSTRAINT ck_swipe_direction CHECK (direction IN (''like'', ''pass'', ''super_like''))', 'ALTER TABLE swipes ADD CONSTRAINT ck_swipe_direction CHECK (direction IN (''like'', ''pass'', ''super_like''))' ); PREPARE migration_statement FROM @statement; EXECUTE migration_statement; DEALLOCATE PREPARE migration_statement;