简体   繁体   中英

MySQL said: Documentation #1005 - Can't create table `music`.`track` (errno: 150 "Foreign key constraint is incorrectly formed")

CREATE DATABASE music DEFAULT CHARACTER SET utf8;
CREATE TABLE Artist
(artist_id INTEGER NOT NULL AUTO_INCREMENT,
 name varchar(255),
 PRIMARY KEY(artist_id)
)
ENGINE = INNODB;
CREATE TABLE Album
(
album_id INTEGER NOT NULL AUTO_INCREMENT,
title varchar(255),
artist_id INTEGER,
PRIMARY KEY(album_id),
INDEX USING BTREE(title),
CONSTRAINT FOREIGN KEY (artist_id)
REFERENCES Artist(Artist_id)
ON DELETE CASCADE ON UPDATE CASCADE   
)
ENGINE = InnoDB;

CREATE TABLE Genre
(
genre_id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
PRIMARY KEY(genre_id),
INDEX USING BTREE (name)
)
ENGINE = INNODB;

CREATE TABLE Track
(
track_id INTEGER NOT NULL AUTO_INCREMENT,
title VARCHAR(255),
len INTEGER,
rating INTEGER,
count INTEGER,
album_id INTEGER,
genre_id INTEGER,
PRIMARY KEY (track_id),
INDEX USING BTREE(title),

CONSTRAINT FOREIGN KEY (album_id) REFERENCES Album(albumn_id)
    ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY(genre_id) REFERENCES Genre(genre_id)
)
ENGINE = INNODB;

I've checked many times. What is the matter?

你拼错了外键

albumn_id

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