Create Table not working Forgive me if the question is very simplistic; I am a bit of a novice when it comes to SQL. The following CREATE TABLE syntax was generated by MySQL workbench from my model; It gives me errno: 150. Anyone who can tell me what I am doing wrong gets a cookie (and my gratitude!).

CREATE TABLE IF NOT EXISTS `mealPlannerApp`.`ingredients` (
`ingredientId` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`stub` VARCHAR(40) NOT NULL,
`name` VARCHAR(40) NULL,
`photo` INT NULL,
`description` TEXT NULL,
`servingSizeInGrams` INT UNSIGNED NULL,
`cost` INT UNSIGNED NULL,
`calories` INT UNSIGNED NULL,
`protein` INT UNSIGNED NOT NULL,
`carboydrates` INT UNSIGNED NOT NULL,
`fat` INT UNSIGNED NOT NULL,
`saturatedFat` INT UNSIGNED NULL,
`transFat` INT UNSIGNED NULL COMMENT ,
`cholesterol` INT UNSIGNED NULL,
`sodium` INT UNSIGNED NULL,
`dietaryFiber` INT UNSIGNED NULL,
`sugars` INT UNSIGNED NULL,
PRIMARY KEY (`ingredientId`),
UNIQUE INDEX `id_UNIQUE` (`ingredientId` ASC),
UNIQUE INDEX `stub_UNIQUE` (`stub` ASC),
INDEX `photo` (`photo` ASC),
INDEX `name` (`name` ASC),
CONSTRAINT `photoId`
FOREIGN KEY (`photo`)
REFERENCES `mealPlannerApp`.`photos` (`photoId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
Error 150 is a FOREIGN KEY related error so I bet that you didn't create the table mealPlannerApp.photos before mealPlannerApp.ingredients (which is mandatory).

Otherwise, you have some bad practices in your query:


PK on ingredientId and unique index id_UNIQUE are duplicates (useless and will generate extra-load)
The ASC option in your indexes definition is understand by MySQL but not implemented (useless), maybe it's Workbench which has generated this.