-1
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..??

closed as off-topic by MDCCL, McNets, John Eisbrener, Marcello Miorelli, mustaccio Sep 30 at 17:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – MDCCL, McNets, John Eisbrener, Marcello Miorelli, mustaccio
If this question can be reworded to fit the rules in the help center, please edit the question.

0

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;

Not the answer you're looking for? Browse other questions tagged or ask your own question.