MySQL: #1064 when adding more than 1 constraint on foreign keys?
-
I've checked it out for 4 times and didn't find any syntax error. Asking for help here and thx!!!! and my MySQL version is 5.5 (for better format, go here: http://stackoverflow.com/questions/13863758/mysql-1064-when-add-more-than-1-constraint-on-foreign-keys) error message is: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADD CONSTRAINT fk_notification_source_idFOREIGN KEY (source_id) REFERENCES ' at line 1 CREATE TABLE IF NOT EXISTS `object_type` ( `type_id` tinyint(1) NOT NULL, `type_name` varchar(45) NOT NULL, `desc` varchar(45) NOT NULL, PRIMARY KEY (`type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;CREATE TABLE IF NOT EXISTS `op_type` ( `type_id` tinyint(1) NOT NULL, `type_name` varchar(45) NOT NULL, `desc` varchar(45) NOT NULL, PRIMARY KEY (`type_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;CREATE TABLE IF NOT EXISTS `user_op` ( `op_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `op_type` tinyint(1) NOT NULL, `op_data` varchar(45) NOT NULL, `time` datetime NOT NULL, PRIMARY KEY (`op_id`, `user_id`), KEY `fk_op_user_id_idx` (`user_id`), KEY `fk_op_op_type_idx` (`op_type`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;CREATE TABLE IF NOT EXISTS `notification_type` ( `type_id` int(11) NOT NULL, `type_name` varchar(45) NOT NULL, `desc` varchar(45) NOT NULL, PRIMARY KEY (`type_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS `user_notification` ( `notif_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `notif_type` int(11) NOT NULL, `source_id` int(11) NOT NULL, `path` varchar(45) NOT NULL, `parent_id` int(11) NOT NULL, `parent_type` tinyint(1) NOT NULL, `count` int(11) NOT NULL, `time` datetime NOT NULL, `lasttimeread` datetime NOT NULL, PRIMARY KEY (`notif_id`, `user_id`), KEY `fk_notification_user_id_idx` (`user_id`), KEY `fk_notification_type_id_idx` (`notif_type`), KEY `fk_notification_source_id_idx` (`source_id`), KEY `fk_notification_parent_type_idx` (`parent_type`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;ALTER TABLE `user_op` ADD CONSTRAINT `fk_op_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, ADD CONSTRAINT `fk_op_op_type` FOREIGN KEY (`op_type`) REFERENCES `op_type` (`type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION;ALTER TABLE `user_notification` ADD CONSTRAINT `fk_notification_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, ADD CONSTRAINT `fk_notification_type_id` FOREIGN KEY (`notif_type`) REFERENCES `notification_type` (`type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, ADD CONSTRAINT `fk_notification_source_id` FOREIGN KEY (`source_id`) REFERENCES `user_op` (`op_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, ADD CONSTRAINT `fk_notification_parent_type` FOREIGN KEY (`parent_type`) REFERENCES `object_type` (`type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION; thank you!!!
-
Answer:
I see two FK references to the user table ALTER TABLE `user_op` ADD CONSTRAINT `fk_op_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ADD CONSTRAINT `fk_notification_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION Do you need both?
Bastien Koert at Quora Visit the source
Related Q & A:
- Is there a recommended and consistent way of adding social buttons?Best solution by User Experience
- How to skip columns empty in CSV file when importing into MySQL table using LOAD DATA INFILE?Best solution by Stack Overflow
- Can a foreign student in U.S. on F-1 visa file taxes as a resident alien if he is here for more than 5yrs?Best solution by Yahoo! Answers
- Is it possible to be a travel nurse when your a single mom of 1 child?Best solution by Yahoo! Answers
- Why are the keys on a calculator opposite to the keys on a phone?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.