I get error 1452 when trying to do this:
ALTER TABLE test.potovanja
ADD CONSTRAINT usr_ind
FOREIGN KEY (username)
REFERENCES test.users (username)
(Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails (test., CONSTRAINT #sql-1110_2_ibfk_1 FOREIGN KEY (username) REFERENCES users (username))). Reference key and referenced key are the same type (VARCHAR).
My SHOW CREATE TABLE outputs:
CREATE TABLE `users` (
`username` varchar(45) NOT NULL,
`password` varchar(45) DEFAULT NULL,
`ime` varchar(45) DEFAULT NULL,
`priimek` varchar(45) DEFAULT NULL,
`nacinp` varchar(45) DEFAULT NULL,
`email` varchar(45) DEFAULT NULL,
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `potovanja` (
`idpotovanja` int(11) NOT NULL AUTO_INCREMENT,
`od` varchar(45) DEFAULT NULL,
`do` varchar(45) DEFAULT NULL,
`datumvstopa` varchar(45) DEFAULT NULL,
`username` varchar(45) DEFAULT NULL,
`cena` varchar(45) DEFAULT NULL,
`datumizstopa` varchar(45) DEFAULT NULL,
PRIMARY KEY (`idpotovanja`),
KEY `usr_ind` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
I really have no idea what to do.