How to allow only a certain type of foreign key in a table
Possible realization.


Main table



CREATE TABLE main ( id INT UNSIGNED PRIMARY KEY, 
                    type VARCHAR(16)
                  );


Prepare main table for referencing



ALTER TABLE main 
    ADD COLUMN for_reference INT UNSIGNED AS (CASE WHEN type LIKE 'allowed%' THEN id END) STORED,
    ADD UNIQUE key_for_reference (for_reference);


Create referenced table



CREATE TABLE slave ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
                     reference INT UNSIGNED,
                     CONSTRAINT fk_to_main FOREIGN KEY (reference) REFERENCES main (for_reference)
                   );




db&lt;>fiddle

PS. Pay attention - the field in main table which is used for referencing primarily (id) must be unique but NOT autoincremented (because the expression of generated column cannot refer to AI). In general this field must be unique but not primary key.