To add a foreign key (grade_id) to an existing table (users), follow the following steps:
ALTER TABLE users ADD grade_id SMALLINT UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE users ADD CONSTRAINT fk_grade_id FOREIGN KEY (grade_id) REFERENCES grades(id);
Simple Steps…
ALTER TABLE t_name1 ADD FOREIGN KEY (column_name) REFERENCES t_name2(column_name)






![SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes](https://blog.rahulbhutani.com/wp-content/uploads/2020/04/123-100x70.jpg)










