简体   繁体   中英

SQL Syntax error foreign key

I've a problem, i try to connect 2 db table, and if I make the query for make a DB structure the answer is Syntax Error.

I paste the code here, somebody can help me ?

DROP TABLE IF EXISTS album;
CREATE TABLE `album` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(30) DEFAULT NULL,
  `description` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=armscii8;

DROP TABLE IF EXISTS picture;
CREATE TABLE `picture` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `id_album` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`id_album`) REFERENCES album(id)
) ENGINE=InnoDB DEFAULT CHARSET=armscii8;

sorry for my bad english.

认为您的id_album必须具有unsigned bean,与album id相同

Just add Unsigned in Foreign key line as follows :

DROP TABLE IF EXISTS album;
CREATE TABLE `album` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(30) DEFAULT NULL,
  `description` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=armscii8;

DROP TABLE IF EXISTS picture;
CREATE TABLE `picture` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `id_album` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`id_album`) REFERENCES album(id)
) ENGINE=InnoDB DEFAULT CHARSET=armscii8;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM