Marcipanas
Marcipanas

Reputation: 161

MySQL Cannot add foreign key constraint Error Code: 1215

I am making a simple MySQL database but i keep getting an error:Cannot add foreign key constraint any help appreciated!
Also a Side question is there any difference between using symbol ` and ' while creating your database?

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`a3823833_MiniPost` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `a3823833_MiniPost`;

/*Table structure for table `user` */

DROP TABLE IF EXISTS `user`;

CREATE TABLE `user` (
  `userid` bigint(10) NOT NULL,
  `username` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  `email` varchar(50) NOT NULL,
  PRIMARY KEY (`userid`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*Table structure for table `profile` */

DROP TABLE IF EXISTS `profile`;

CREATE TABLE `profile` (
  `userid` int(11),
  `lastName` varchar(50),
  `firstName` varchar(50),
  `dob` varchar(10),
  PRIMARY KEY (`userid`),
  CONSTRAINT `profile_fk` FOREIGN KEY (`userid`) REFERENCES `user` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Upvotes: 1

Views: 53

Answers (1)

Drew
Drew

Reputation: 24959

the bigint(10) and int(11) are not the same. make em same, and pk on parent table (as u are)

Upvotes: 2

Related Questions