SQL WORKBENCH: REFERENCES in foreign key command error "REFERENCES" is not valid in this position, expecting( '('

Viewed 1069

My REFERENCES keeps getting this error in MySQL Workbench. Here is the code

Use my_database;

Create table bands (
id int NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
primary key (id)
);
Create Table albums(
 id int Not NUll auto_increment,
 name Varchar(255) NOT NULL,
 release_year INT,
 band_id INT NOT NULL,
 primary key (id),
 foreign key band_id references bands(id)
 );
1 Answers

You forget to put ( and ) bracket between foreign key

CREATE TABLE albums(
 id int Not NUll AUTO_INCREMENT,
 name Varchar(255) NOT NULL,
 release_year INT,
 band_id INT NOT NULL,
 PRIMARY KEY (id),
 FOREIGN KEY (band_id) REFERENCES bands(id)
 );
Related