MySQL Error1822 failed to add the foreign key constraint Im trying to have the City and Postal Code depend on eachother, but i get this error time and time again.
MySQL Error1822 failed to add the foreign key constraint. Missing index for constraint 'Student_address_ibfk_1' in the referenced table 'Student_Information'
################
CREATE TABLE IF NOT EXISTS Student_Information(

    Attendance_ID INT NOT NULL AUTO_INCREMENT,
    Student_ID INT NOT NULL,
    Student_name VARCHAR(99) NOT NULL,
    Phone_number INT NOT NULL,
    Email VARCHAR(99) NOT NULL,
    City VARCHAR(99) NOT NULL,

    PRIMARY KEY(Attendance_ID, Student_ID, City)

);

CREATE TABLE IF NOT EXISTS Post_Address (

    Student_ID INT NOT NULL,
    Street_Address VARCHAR(99) NOT NULL,
    Postal_Code INT NOT NULL,
    City VARCHAR(99) NOT NULL,

    PRIMARY KEY(Student_ID, City)

);

CREATE TABLE IF NOT EXISTS Attendance(

    Attendance_ID INT NOT NULL AUTO_INCREMENT,
    4_jan INT NOT NULL,
    6_feb INT NOT NULL,
    7_mar INT NOT NULL,
    18_apr INT NOT NULL,
    20_may INT NOT NULL,
    21_jun INT NOT NULL,
    10_jul INT NOT NULL,
    30_aug INT NOT NULL,
    16_oct INT NOT NULL,
    12_nov INT NOT NULL,
    15_des INT NOT NULL,

    PRIMARY KEY(Attendance_ID)
);
I made tables and I used index to be able to make a relationship between my tables, then I added a foreign key (the relationship is one-to-many).
FYI, you don't need to repeat the column in a different table(city). You can save the data in one table and you get the data by joining them. I kept the city on both tables, but you can remove it from one of your tables.

CREATE TABLE `Attendance` (
  `id` int(11) NOT NULL PRIMARY KEY  AUTO_INCREMENT,
  `Attendance_ID` int(11) NOT NULL,
  `4_jan` int(11) NOT NULL,
  `6_feb` int(11) NOT NULL,
  `7_mar` int(11) NOT NULL,
  `18_apr` int(11) NOT NULL,
  `20_may` int(11) NOT NULL,
  `21_jun` int(11) NOT NULL,
  `10_jul` int(11) NOT NULL,
  `30_aug` int(11) NOT NULL,
  `16_oct` int(11) NOT NULL,
  `12_nov` int(11) NOT NULL,
  `15_des` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `Post_Address` (
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `Student_ID` int(11) NOT NULL,
  `Street_Address` varchar(99) NOT NULL,
  `Postal_Code` int(11) NOT NULL,
  `City` varchar(99) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `Student_Information` (
  `Id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT ,
  `Attendance_ID` int(11) NOT NULL,
  `Student_ID` int(11) NOT NULL,
  `Student_name` varchar(99) NOT NULL,
  `Phone_number` int(11) NOT NULL,
  `Email` varchar(99) NOT NULL,
  `City` varchar(99) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `Attendance`
  ADD KEY `Attendance_ID` (`Attendance_ID`);

ALTER TABLE `Post_Address`
  ADD KEY `Student_ID` (`Student_ID`);

ALTER TABLE `Student_Information`
  ADD KEY `Attendance_ID` (`Attendance_ID`),
  ADD KEY `Student_ID` (`Student_ID`);

ALTER TABLE `Attendance`
  ADD CONSTRAINT `attendance_ibfk_1` FOREIGN KEY (`Attendance_ID`) REFERENCES `Student_Information` (`Attendance_ID`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `Post_Address`
  ADD CONSTRAINT `post_address_ibfk_1` FOREIGN KEY (`Student_ID`) REFERENCES `Student_Information` (`Student_ID`) ON DELETE CASCADE ON UPDATE CASCADE;