Results 1 to 3 of 3

Thread: Foreign Key related MySQL error

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Foreign Key related MySQL error

    Hi..guys! I having l error in query statement related to foreign key creation,

    MySQL said:
    #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 '(`reserve_id`)
    FOREIGN KEY (`movie_id`) REFERENCES `movie` (`movie_id`)
    FOR' at line 9


    The table below can't be loaded,
    Code:
    CREATE TABLE `reserve` (
      `reserve_id` int(4) NOT NULL auto_increment,
      `date` date NOT NULL,
      `time` time NOT NULL,
      `seat_qty` int(2) NOT NULL,
      `ref_code` varchar(50) collate latin1_general_ci NOT NULL,
      `movie_id` int(4) NOT NULL,
      `member_id`int(4) NOT NULL
      PRIMARY KEY  (`reserve_id`)
      FOREIGN KEY  (`movie_id`) REFERENCES `movie` (`movie_id`)
      FOREIGN KEY  (`member_id`) REFERENCES `member` (`member_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

    The foreign keys are refered to these two tables
    Code:
    CREATE TABLE `movie` (
      `movie_id` int(4) NOT NULL auto_increment,
      `name` varchar(100) collate latin1_general_ci NOT NULL,
      `director` varchar(50) collate latin1_general_ci NOT NULL,
      `casting` varchar(1000) collate latin1_general_ci NOT NULL,
      `duration` time NOT NULL,
      `classification` char(4) collate latin1_general_ci NOT NULL,
      `language` char(30) collate latin1_general_ci NOT NULL,
      `synopsis` varchar(3000) collate latin1_general_ci NOT NULL,
      `screeningTime` varchar(200) collate latin1_general_ci NOT NULL,
      PRIMARY KEY  (`movie_id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=8 ;
    Code:
    CREATE TABLE `member` (
      `member_id` int(4) NOT NULL auto_increment,
      `name` varchar(50) collate latin1_general_ci NOT NULL,
      `email` varchar(50) collate latin1_general_ci NOT NULL,
      `password` varchar(15) collate latin1_general_ci NOT NULL,
      `telephone` char(10) collate latin1_general_ci NOT NULL,
      `address` varchar(70) collate latin1_general_ci NOT NULL,
      PRIMARY KEY  (`member_id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;

  2. #2
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Problem resolved.I forgot some commas..

  3. #3
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh my god, was looking for THIS answer for a hour now. Thank you!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •