errno: 150 "Foreign key constraint is incorrectly formed" CREATE TABLE IF NOT EXISTS `Register_Per` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `Name` varchar(50) NOT NULL,
 `DOB` varchar(20) NOT NULL,
 `Gender` CHARACTER(8) NOT NULL,
 `ConNo` int(11) NOT NULL UNIQUE,
 `Email` varchar(50) NOT NULL,
    PRIMARY KEY (`id`)
 );


CREATE TABLE IF NOT EXISTS `login`(
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(20) NOT NULL,
    PRIMARY KEY (`username`),
FOREIGN KEY(`id`) REFERENCES `Register_Per`(`id`) 
);


CREATE TABLE `images` (
 `id` int(11) NOT NULL AUTO_INCREMENT UNIQUE,
 `file_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `uploaded_on` datetime NOT NULL,
 `submittedby` varchar(50),
 FOREIGN KEY(`submittedby`) REFERENCES `login`(`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


What to change in this..??
It starts to work on 5.7.27 if second table uses matching DEFAULT CHARSET and COLLATE options:

CREATE TABLE IF NOT EXISTS `login`(
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varchar(50) NOT NULL,
    `password` varchar(20) NOT NULL,
    PRIMARY KEY (`username`),
    FOREIGN KEY(`id`) REFERENCES `Register_Per`(`id`) 
) Engine=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;