0

PARENT TABLE : app

  • Parent table app having two columns ID,APP-ID.

id int(11) not null auto_increment, `App-id varchar(20) NOT NULL latin1_bin,

Table column description: - ID = auto increment - APP-ID = varchar with collation type latin1_bin

CHILD TBALE : app_ser

  • Child table app_ser having two columns ID,APP-NAME

id int(11) not null auto_increment, *`App-name varchar(20) NOT NULL latin1_swedish_ci,**

Table column description: - ID = auto increment - App_Name = varchar with collation type latin1_swedish_ci

My_goal_is:

1) Now i want add a "primary key" on parent table column App-id.

query cmd is : alter table app ADD PRIMARY KEY (App-id)

2) Next i am going to add "foreign key" on child table column App-name.

query cmd is : alter table app_ser ADD CONSTRAINT `fk_app_ser` FOREIGN KEY (`APP_NAME`) REFERENCES `app` (`APP_ID`)

Now I have issue on while run the foreign key query with error code 1215. could you please help me on this ?

Thanks, viswa

viswa
  • 51
  • 1
  • 9
  • 1. The collations must be the same. Period. 2. Why do you reference the varchar field and not the id, which is integer? – Shadow Jan 18 '16 at 14:40
  • Hi Shadow Thanks for your reply i will change my collation type as required. second thing is reference the varchar field and not integer. – viswa Jan 18 '16 at 14:49
  • It's because your 1st command is not running successfully. – Dhruv Kapatel Jan 18 '16 at 14:51
  • It is not recommended to use primary key with varchar type. http://stackoverflow.com/questions/19299874/can-i-use-varchar-as-the-primary-key – Dhruv Kapatel Jan 18 '16 at 14:58

0 Answers0