Hello,
there is a wrong primary key reference in your code, examine red-coloured lines:
USE streamlibrary;
DROP TABLE IF EXISTS streamlibrary.FileProperties ;
CREATE TABLE IF NOT EXISTS streamlibrary.FileProperties(
PK_fileName VARCHAR(50) NOT NULL,
extension VARCHAR(4) NOT NULL ,
sizeMB DECIMAL(3) NOT NULL ,
location VARCHAR(50) NOT NULL ,
data VARCHAR(45) NOT NULL ,
name VARCHAR(45) NOT NULL ,
PRIMARY KEY (PK_fileName)
);
-- -----------------------------------------------------
-- Table streamlibrary.AudioCodec
-- -----------------------------------------------------
DROP TABLE IF EXISTS streamlibrary.AudioCodec;
CREATE TABLE IF NOT EXISTS streamlibrary.AudioCodec(
PK_audioCodecID INT NOT NULL AUTO_INCREMENT,
format VARCHAR(20) NOT NULL,
bitRate INT NOT NULL,
PRIMARY KEY (PK_audioCodecID)
);
-- -----------------------------------------------------
-- Table streamlibrary.Audio
-- -----------------------------------------------------
DROP TABLE IF EXISTS streamlibrary.Audio;
CREATE TABLE IF NOT EXISTS streamlibrary.Audio(
PK_audioID INT NOT NULL AUTO_INCREMENT ,
fileName VARCHAR(50) NOT NULL ,
codec INT NOT NULL ,
sampleRate VARCHAR(4) NOT NULL ,
channel VARCHAR(45) NOT NULL ,
content VARCHAR(45) NOT NULL,
PRIMARY KEY (PK_audioID),
FOREIGN KEY (fileName) REFERENCES FileProperties(fileName),
FOREIGN KEY (codec) REFERENCES AudioCodec(PK_audioCodecID)
);
Be sure that your database engine is always innodb. If not, foreign keys are entirely useless.
Btw, if there exists a many-to-many relationship between FileProperties and AudioCodec, then primary key of Audio, which obviously is the linking table to making up this relationship, must be at least (PK_fileName, codec). Sometimes this pair of column names is not unique, therefore "at least", additional column must be added to pk. If there are doubts on my suggestion, ask me.
-- tesu