My SQL script firstly says that it is not connected, when i open it, so i connect it by going to Query -> Reconnect to server, which works. Then i try to execute the SQL script which only creates the first two tables are met with an error code 1064, and the errors are at the VISIBLE Index lines. I have no idea what that means as i am completely new to SQL, can anyone help?
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' INDEX userId_idx (userId ASC) VISIBLE, CONSTRAINT gameId FOREIGN ' at line 9
-- MySQL Script generated by MySQL Workbench
-- Wed Jan 2 02:21:44 2019
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema game_review
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema game_review
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `game_review` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ;
USE `game_review` ;
-- -----------------------------------------------------
-- Table `game_review`.`games`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `game_review`.`games` (
`game_Id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NOT NULL,
`tags` VARCHAR(60) NOT NULL,
`systemReq` VARCHAR(255) NOT NULL,
`developer` VARCHAR(45) NOT NULL,
`publisher` VARCHAR(45) NOT NULL,
`trailer` VARCHAR(45) NULL,
`about` VARCHAR(255) NULL,
`platform` VARCHAR(45) NOT NULL,
`categories` VARCHAR(45) NOT NULL,
`description` VARCHAR(45) NOT NULL,
`releaseDate` DATETIME NOT NULL,
PRIMARY KEY (`game_Id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `game_review`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `game_review`.`users` (
`user_Id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(45) NOT NULL,
`email` VARCHAR(45) NOT NULL,
PRIMARY KEY (`user_Id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `game_review`.`reviews`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `game_review`.`reviews` (
`review_Id` INT NOT NULL AUTO_INCREMENT,
`gameId` INT NOT NULL,
`userId` INT NOT NULL,
`review` TEXT(1024) NOT NULL,
`rating` INT NULL,
`dateposted` DATETIME NULL,
PRIMARY KEY (`review_Id`),
INDEX `gameId_idx` (`gameId` ASC) VISIBLE,
INDEX `userId_idx` (`userId` ASC) VISIBLE,
CONSTRAINT `gameId`
FOREIGN KEY (`gameId`)
REFERENCES `game_review`.`games` (`game_Id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `userId`
FOREIGN KEY (`userId`)
REFERENCES `game_review`.`users` (`user_Id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `game_review`.`favourites`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `game_review`.`favourites` (
`favourites_Id` INT NOT NULL AUTO_INCREMENT,
`gameId` INT NOT NULL,
`userId` INT NOT NULL,
PRIMARY KEY (`favourites_Id`),
INDEX `gameId_idx` (`gameId` ASC) VISIBLE,
INDEX `userId_idx` (`userId` ASC) VISIBLE,
CONSTRAINT `gameId`
FOREIGN KEY (`gameId`)
REFERENCES `game_review`.`games` (`game_Id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `userId`
FOREIGN KEY (`userId`)
REFERENCES `game_review`.`users` (`user_Id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `game_review`.`forum`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `game_review`.`forum` (
`forum_Id` INT NOT NULL AUTO_INCREMENT,
`gameId` INT NOT NULL,
`userId` INT NOT NULL,
`topic` VARCHAR(45) NOT NULL,
`views` INT NOT NULL,
`likes` INT NOT NULL,
`comment` TEXT(300) NULL,
`totalComments` INT NULL,
`dateposted` DATETIME NOT NULL,
PRIMARY KEY (`forum_Id`),
INDEX `gameId_idx` (`gameId` ASC) VISIBLE,
INDEX `userId_idx` (`userId` ASC) VISIBLE,
CONSTRAINT `gameId`
FOREIGN KEY (`gameId`)
REFERENCES `game_review`.`games` (`game_Id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `userId`
FOREIGN KEY (`userId`)
REFERENCES `game_review`.`users` (`user_Id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `game_review`.`game cart`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `game_review`.`game cart` (
`cart_Id` INT NOT NULL AUTO_INCREMENT,
`gameId` INT NOT NULL,
`quantity` INT NULL,
PRIMARY KEY (`cart_Id`),
INDEX `gameId_idx` (`gameId` ASC) VISIBLE,
CONSTRAINT `gameId`
FOREIGN KEY (`gameId`)
REFERENCES `game_review`.`games` (`game_Id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=#OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;
Your declaration of indexes is not correct : VISIBLE is not recognized syntax. Also, the ASC mention is superfluous as it corrresponds to the default.
Replace :
...
INDEX `gameId_idx` (`gameId` ASC) VISIBLE,
INDEX `userId_idx` (`userId` ASC) VISIBLE,
...
With :
...
INDEX `reviews_gameId_idx` (`gameId`),
INDEX `reviews_userId_idx` (`userId`),
...
For more information see the mysql CREATE INDEX docs.
Also please bear in mind that, in most RDBMS others than mysql, index names are global across the database schema, hence make sure not to use the same index name twice (I can see that at least index gameId_idx is declared twice. One solution is to prefix the index name with the table it belongs to, as shown above.
Foreign key names between different tables also must be unique (you have duplicates like game_Id).
Finally I also notice that one of your table name has a space in it (game cart) : this is not a good practice, should be avoided.
Related
i don't know much SQLs, i generated this using modelling via MySQL Workbench. I always get a Error Code: 1826. Duplicate foreign key constraint name 'post_id' when i try to import the SQL generated via Forward Engineering of workbench. If anybody could me out. I am not coding this from scratch. I just made a ERD and generated an SQL.
Additional info, the error fires in this line
CREATE TABLE IF NOT EXISTS testing.post_likes ...
Also, MySQL Workbench and Server are both version 8.0.19
Here is the generated SQL
-- MySQL Script generated by MySQL Workbench
-- Tue Mar 31 21:51:19 2020
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema testing
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema testing
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `testing` DEFAULT CHARACTER SET utf8 ;
USE `testing` ;
-- -----------------------------------------------------
-- Table `testing`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `testing`.`users` (
`userid` DOUBLE NOT NULL,
`username` VARCHAR(100) NULL,
`email` VARCHAR(100) NULL,
`name` VARCHAR(100) NULL,
`handle` VARCHAR(45) NULL,
`quote` LONGTEXT NULL,
`last_updated` DATE NULL,
PRIMARY KEY (`userid`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `testing`.`posts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `testing`.`posts` (
`post_id` DOUBLE NOT NULL,
`user_id` DOUBLE NOT NULL,
`description` LONGTEXT NULL,
`images` LONGTEXT NULL,
`tags` LONGTEXT NULL,
`last_updated` DATE NULL,
PRIMARY KEY (`post_id`),
INDEX `user_id_idx` (`user_id` ASC) VISIBLE,
CONSTRAINT `user_id`
FOREIGN KEY (`user_id`)
REFERENCES `testing`.`users` (`userid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `testing`.`comments`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `testing`.`comments` (
`comment_id` DOUBLE NOT NULL,
`post_id` DOUBLE NOT NULL,
`description` LONGTEXT NULL,
`images` LONGTEXT NULL,
`last_updated` DATE NULL,
PRIMARY KEY (`comment_id`),
INDEX `post_id_idx` (`post_id` ASC) VISIBLE,
CONSTRAINT `post_id`
FOREIGN KEY (`post_id`)
REFERENCES `testing`.`posts` (`post_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `testing`.`post_likes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `testing`.`post_likes` (
`plike_id` DOUBLE NOT NULL,
`post_id` DOUBLE NOT NULL,
`user_id` DOUBLE NOT NULL,
`type` INT NULL,
PRIMARY KEY (`plike_id`),
INDEX `post_id_idx` (`post_id` ASC) VISIBLE,
INDEX `user_id_idx` (`user_id` ASC) VISIBLE,
CONSTRAINT `post_id`
FOREIGN KEY (`post_id`)
REFERENCES `testing`.`posts` (`post_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `user_id`
FOREIGN KEY (`user_id`)
REFERENCES `testing`.`users` (`userid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `testing`.`comment_likes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `testing`.`comment_likes` (
`clike_id` DOUBLE NOT NULL,
`comment_id` DOUBLE NOT NULL,
`user_id` DOUBLE NOT NULL,
`type` INT NULL,
PRIMARY KEY (`clike_id`),
INDEX `comment_id_idx` (`comment_id` ASC) VISIBLE,
INDEX `user_id_idx` (`user_id` ASC) VISIBLE,
CONSTRAINT `comment_id`
FOREIGN KEY (`comment_id`)
REFERENCES `testing`.`comments` (`comment_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `user_id`
FOREIGN KEY (`user_id`)
REFERENCES `testing`.`users` (`userid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=#OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;
As per discussion with #P.Salmon, it was indicated that the FK name was duplicated. So i adjusted the FK name via the ERD ang generated a new SQL file. So basically, i adjusted avoid using the same FK name and voila, it works.
See below
I'm forward engineering a database from an ERD that I created in MySqlWorkbench. I have a very basic many to many relationship between the "gyms" table and the "instructors" table, but I'm getting the error above. To me, the error reads that MySql can't find the "gym_id" column in the "gyms" table when it tries to create the many-to-many table.
I don't know why that would be the case.
I've went through the tables to make sure there were no typos and that the data types matched. I also went through the execution script to make sure the "gyms" table was being created before the many-to-many. It was. I can't sniff out what is causing the error. So any help or suggestion is appreciated
This is the error:
Executing SQL script in server
ERROR: Error 3734: Failed to add the foreign key constraint. Missing column 'gym_id' for constraint 'fk_gyms_instructors_gyms' in the referenced table 'gyms'
SQL Code:
-- -----------------------------------------------------
-- Table `fitness`.`gyms_instructors`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`gyms_instructors` (
`id` INT NOT NULL AUTO_INCREMENT,
`gym_id` SMALLINT NOT NULL,
`instructor_id` SMALLINT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_gyms_instructors_gyms_idx` (`gym_id` ASC) VISIBLE,
INDEX `fk_gyms_instructors_instructors_idx` (`instructor_id` ASC) VISIBLE,
CONSTRAINT `fk_gyms_instructors_gyms`
FOREIGN KEY (`gym_id`)
REFERENCES `fitness`.`gyms` (`gym_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_gyms_instructors_instructors`
FOREIGN KEY (`instructor_id`)
REFERENCES `fitness`.`instructors` (`instructor_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB
SQL script execution finished: statements: 10 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
The other potentially useful information is:
1. On the many to many table, in the foreign keys section both gym_id and instructor_id are SMALLINTS and NOT NULL,
2. On their respective table the gym_id and instructor_id are autoincrementing primary keys, NOT NULL
3. I pasted the full script below if you want to look.
-- MySQL Workbench Forward Engineering
SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema fitness
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema fitness
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `fitness` DEFAULT CHARACTER SET utf8 ;
USE `fitness` ;
-- -----------------------------------------------------
-- Table `fitness`.`fitness_classes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`fitness_classes` (
`fitness_class_id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NOT NULL,
`price` DECIMAL(2,2) NOT NULL,
`description` VARCHAR(500) NOT NULL,
`vacancies` INT NOT NULL,
`start_time` DATETIME NOT NULL,
PRIMARY KEY (`fitness_class_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`categories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`categories` (
`category_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`description` TEXT(1200) NULL,
PRIMARY KEY (`category_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`tags`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`tags` (
`id` INT NOT NULL AUTO_INCREMENT,
`fitness_class_id` INT NOT NULL,
`category_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_tags_fitness_classes_idx` (`fitness_class_id` ASC) VISIBLE,
INDEX `fk_tags_categories_idx` (`category_id` ASC) VISIBLE,
CONSTRAINT `fk_tags_fitness_classes`
FOREIGN KEY (`fitness_class_id`)
REFERENCES `fitness`.`fitness_classes` (`fitness_class_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_tags_categories`
FOREIGN KEY (`category_id`)
REFERENCES `fitness`.`categories` (`category_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`gyms`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`gyms` (
`gym_id` SMALLINT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(55) NOT NULL,
`address` VARCHAR(55) NOT NULL,
`city` VARCHAR(25) NOT NULL,
`state` VARCHAR(25) NOT NULL,
`phone` VARCHAR(10) NOT NULL,
`latitude` DECIMAL(10,8) NULL,
`longitude` DECIMAL(10,8) NULL,
`neighborhood` VARCHAR(45) NOT NULL,
`create_time` TIMESTAMP NOT NULL,
PRIMARY KEY (`gym_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`instructors`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`instructors` (
`instructor_id` SMALLINT NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(55) NOT NULL,
`last_name` VARCHAR(55) NOT NULL,
`create_time` TIMESTAMP NOT NULL,
PRIMARY KEY (`instructor_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`gyms_instructors`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`gyms_instructors` (
`id` INT NOT NULL AUTO_INCREMENT,
`gym_id` SMALLINT NOT NULL,
`instructor_id` SMALLINT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_gyms_instructors_gyms_idx` (`gym_id` ASC) VISIBLE,
INDEX `fk_gyms_instructors_instructors_idx` (`instructor_id` ASC) VISIBLE,
CONSTRAINT `fk_gyms_instructors_gyms`
FOREIGN KEY (`gym_id`)
REFERENCES `fitness`.`gyms` (`gym_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_gyms_instructors_instructors`
FOREIGN KEY (`instructor_id`)
REFERENCES `fitness`.`instructors` (`instructor_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`listings`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`listings` (
`id` INT NOT NULL AUTO_INCREMENT,
`gym_id` SMALLINT NOT NULL,
`fitness_class_id` INT NOT NULL,
`instructor_id` SMALLINT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_listings_gym_idx` (`gym_id` ASC) VISIBLE,
INDEX `fk_listings_fitness_class_idx` (`fitness_class_id` ASC) VISIBLE,
INDEX `fk_listings_instructor_idx` (`instructor_id` ASC) VISIBLE,
CONSTRAINT `fk_listings_gym`
FOREIGN KEY (`gym_id`)
REFERENCES `fitness`.`gyms` (`gym_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_listings_fitness_class`
FOREIGN KEY (`fitness_class_id`)
REFERENCES `fitness`.`fitness_classes` (`fitness_class_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_listings_instructor`
FOREIGN KEY (`instructor_id`)
REFERENCES `fitness`.`instructors` (`instructor_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`users` (
`user_id` INT NOT NULL AUTO_INCREMENT,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(32) NOT NULL,
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`username` VARCHAR(16) NOT NULL,
PRIMARY KEY (`user_id`));
-- -----------------------------------------------------
-- Table `fitness`.`reviews`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`reviews` (
`review_id` INT NOT NULL AUTO_INCREMENT,
`fitness_class_id` INT NOT NULL,
`rating` TINYINT(1) NOT NULL,
`review_text` TEXT(1200) NULL,
`create_time` TIMESTAMP NOT NULL,
PRIMARY KEY (`review_id`),
INDEX `fk_reviews_classes_idx` (`fitness_class_id` ASC) VISIBLE,
CONSTRAINT `fk_reviews_classes`
FOREIGN KEY (`fitness_class_id`)
REFERENCES `fitness`.`fitness_classes` (`fitness_class_id`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `fitness`.`bookings`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `fitness`.`bookings` (
`booking_id` INT NOT NULL AUTO_INCREMENT,
`fitness_class_id` INT NOT NULL,
`user_id` INT NOT NULL,
`price` DECIMAL(2,2) NOT NULL,
`class_start_time` DATETIME NOT NULL,
`purchase_date` DATETIME NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`booking_id`),
CONSTRAINT `user_id`
FOREIGN KEY ()
REFERENCES `fitness`.`users` ()
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fitness_class_id`
FOREIGN KEY ()
REFERENCES `fitness`.`fitness_classes` ()
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;
SET SQL_MODE=#OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;
I'm trying to forward engineer my ERD that I made, but the Forward Engineer Process gives me as output an error. ERROR: Error 3734: Failed to add the foreign key constraint. Missing column 'straatid' for constraint 'verzinzelf3' in the referenced table 'locatie'.
But that is very odd, because the columnname straatid is in fact in the table Locatie. The relation between table Team and Locatie is exactly the same as the relation between Locatie and Plant, but it seems that I only get an error between the relation of table Locatie and Plant. I can't really figure out how to solve this error. Can someone maybe help me with this problem?.
This is the review of the SQL script that is supposed to be executed:
-- MySQL Workbench Forward Engineering
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`table1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`table1` (
`StraatID` VARCHAR(45) NOT NULL,
`Straat` VARCHAR(45) NULL,
`Latitude` VARCHAR(45) NULL,
`Longitude` VARCHAR(45) NULL,
PRIMARY KEY (`StraatID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Locatie`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Locatie` (
`Huisnr` VARCHAR(45) NOT NULL,
`StraatID` VARCHAR(45) NOT NULL,
`Toevoeging` VARCHAR(45) NULL,
PRIMARY KEY (`Huisnr`, `StraatID`),
UNIQUE INDEX `StraatID_UNIQUE` (`StraatID` ASC) VISIBLE,
UNIQUE INDEX `Huisnr_UNIQUE` (`Huisnr` ASC) VISIBLE,
INDEX `verzinzelf2_idx` (`StraatID` ASC) VISIBLE,
CONSTRAINT `verzinzelf2`
FOREIGN KEY (`StraatID`)
REFERENCES `mydb`.`table1` (`StraatID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Team`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Team` (
`Teamnr` INT NOT NULL,
`StraatID` VARCHAR(45) NOT NULL,
`Huisnr` VARCHAR(45) NOT NULL,
`StraatID1` VARCHAR(45) NOT NULL,
PRIMARY KEY (`Teamnr`),
INDEX `verzinzelf5_idx` (`Huisnr` ASC, `StraatID1` ASC) VISIBLE,
CONSTRAINT `verzinzelf5`
FOREIGN KEY (`Huisnr` , `StraatID1`)
REFERENCES `mydb`.`Locatie` (`Huisnr` , `StraatID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Eigenaar`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Eigenaar` (
`Eigenaar` INT NOT NULL,
PRIMARY KEY (`Eigenaar`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Plant`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Plant` (
`Plant beschrijving` VARCHAR(45) NOT NULL,
`Kaartlokatie` VARCHAR(45) NOT NULL,
`Oppervlakte` VARCHAR(45) NOT NULL,
`Eigenaar` INT NOT NULL,
`Huisnr` VARCHAR(45) NOT NULL,
`StraatID` VARCHAR(45) NOT NULL,
PRIMARY KEY (`Plant beschrijving`, `Kaartlokatie`, `Oppervlakte`),
INDEX `verzinzelf4_idx` (`Eigenaar` ASC) VISIBLE,
INDEX `verzinzelf3_idx` (`Huisnr` ASC, `StraatID` ASC) VISIBLE,
CONSTRAINT `verzinzelf4`
FOREIGN KEY (`Eigenaar`)
REFERENCES `mydb`.`Eigenaar` (`Eigenaar`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `verzinzelf3`
FOREIGN KEY (`Huisnr` , `StraatID`)
REFERENCES `mydb`.`Locatie` (`Huisnr` , `StraatID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Meting`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Meting` (
`Teamnr` INT NOT NULL,
`Plant` VARCHAR(45) NOT NULL,
`Meetsoort` VARCHAR(45) NULL,
PRIMARY KEY (`Teamnr`, `Plant`),
INDEX `verzinzelf1_idx` (`Plant` ASC) VISIBLE,
INDEX `verzinzelf_idx` (`Teamnr` ASC) VISIBLE,
CONSTRAINT `verzinzelf`
FOREIGN KEY (`Teamnr`)
REFERENCES `mydb`.`Team` (`Teamnr`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `verzinzelf1`
FOREIGN KEY (`Plant`)
REFERENCES `mydb`.`Plant` (`Plant beschrijving`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
And the full error message:
Executing SQL script in server
ERROR: Error 3734: Failed to add the foreign key constraint. Missing column 'straatid' for constraint 'verzinzelf3' in the referenced table 'locatie'
SQL Code:
-- -----------------------------------------------------
-- Table `mydb`.`Plant`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Plant` (
`Plant beschrijving` VARCHAR(45) NOT NULL,
`Kaartlokatie` VARCHAR(45) NOT NULL,
`Oppervlakte` VARCHAR(45) NOT NULL,
`Eigenaar` INT NOT NULL,
`Huisnr` VARCHAR(45) NOT NULL,
`StraatID` VARCHAR(45) NOT NULL,
PRIMARY KEY (`Plant beschrijving`, `Kaartlokatie`, `Oppervlakte`),
INDEX `verzinzelf4_idx` (`Eigenaar` ASC) VISIBLE,
INDEX `verzinzelf3_idx` (`Huisnr` ASC, `StraatID` ASC) VISIBLE,
CONSTRAINT `verzinzelf4`
FOREIGN KEY (`Eigenaar`)
REFERENCES `mydb`.`Eigenaar` (`Eigenaar`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `verzinzelf3`
FOREIGN KEY (`Huisnr` , `StraatID`)
REFERENCES `mydb`.`Locatie` (`Huisnr` , `StraatID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
SOLVED: By removing the primary key atribute from the foreign keys.
I'm building an SQL Database for an school, to keep track of teachers, students, groups and payments.
I have set all the foreign keys to cascade on update (since I believe it's going to be the best way), but I want to set them to null on delete (ie: if someones deletes a group, students can be assigned to another group with an update), but the server gives me this message in tables grupo and grupoalumno when I try to create the database:
Error: 150 "Foreign key constraint is incorrectly formed".
I have the foreign keys with not null unchecked (which means a foreign key can be a null value), and from what I understood, solution is to set the primary keys being referenced as being able to be null, which makes me question if it would be a good idea to have a PK null.
I have also considered restricting the delete, and only using updates (ie: editing a group until it's right instead of deleting it), but I think being able to actually delete a group without cascading the whole database would be wise.
I'm creating the tables in the order they need to be (ie: not creating a table that references a key that hasn't been created yet.
I'm using PHPMyAdmin and MySQL Workbench. I believe MySQL exports the database with InnoDB as the engine.
I hope I explained myself. Thanks in advance. Hoping to learn a lot!
Code:
-- MySQL Script generated by MySQL Workbench
-- 10/29/18 21:25:26
-- Model: New Model Version: 1.0
SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema celex
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `celex` DEFAULT CHARACTER SET utf8 COLLATE utf8_spanish_ci ;
USE `celex` ;
-- -----------------------------------------------------
-- Table `celex`.`Grupo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`Grupo` (
`idGrupo` INT NOT NULL AUTO_INCREMENT,
`idioma` VARCHAR(45) NOT NULL,
`nivel` VARCHAR(45) NOT NULL,
`horarioInicio` TIME NULL,
`horarioTermino` TIME NULL,
PRIMARY KEY (`idGrupo`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `celex`.`Alumno`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`Alumno` (
`idAlumno` INT NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR(45) NOT NULL,
`primerApellido` VARCHAR(45) NOT NULL,
`segundoApellido` VARCHAR(45) NOT NULL,
`email` VARCHAR(45) NOT NULL,
`telefono` VARCHAR(45) NULL,
`edad` INT NULL,
`procedencia` VARCHAR(45) NULL,
`fechaIngreso` DATE NOT NULL,
`nivelIngreso` VARCHAR(45) NOT NULL,
`moduloIngreso` INT NOT NULL,
`nivelColocacion` VARCHAR(45) NULL,
`moduloColocacion` INT NULL,
PRIMARY KEY (`idAlumno`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `celex`.`Periodo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`Periodo` (
`idPeriodo` INT NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR(45) NULL,
`inicio` DATE NOT NULL,
`termino` DATE NOT NULL,
PRIMARY KEY (`idPeriodo`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `celex`.`GrupoAlumno`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`GrupoAlumno` (
`idGrupoAlumno` INT NOT NULL AUTO_INCREMENT,
`modulo` INT NOT NULL,
`calificacionParcial` DOUBLE NULL,
`calificacionFinal` DOUBLE NULL,
`calificacionExtra` DOUBLE NULL,
`Periodo_idPeriodo` INT NULL,
`Grupo_idGrupo` INT NULL,
`Alumno_idAlumno` INT NULL,
PRIMARY KEY (`idGrupoAlumno`, `Periodo_idPeriodo`, `Grupo_idGrupo`, `Alumno_idAlumno`),
INDEX `fk_Grupo_has_Alumno_Alumno1_idx` (`Alumno_idAlumno` ASC),
INDEX `fk_Grupo_has_Alumno_Grupo_idx` (`Grupo_idGrupo` ASC),
INDEX `fk_GrupoAlumno_Periodo1_idx` (`Periodo_idPeriodo` ASC),
CONSTRAINT `fk_Grupo_has_Alumno_Grupo`
FOREIGN KEY (`Grupo_idGrupo`)
REFERENCES `celex`.`Grupo` (`idGrupo`)
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Grupo_has_Alumno_Alumno1`
FOREIGN KEY (`Alumno_idAlumno`)
REFERENCES `celex`.`Alumno` (`idAlumno`)
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_GrupoAlumno_Periodo1`
FOREIGN KEY (`Periodo_idPeriodo`)
REFERENCES `celex`.`Periodo` (`idPeriodo`)
ON DELETE SET NULL
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `celex`.`PeriodoAlumno`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`PeriodoAlumno` (
`idPeriodoAlumno` INT NOT NULL AUTO_INCREMENT,
`cuota` TINYINT(1) NULL,
`Periodo_idPeriodo` INT NULL,
`Alumno_idAlumno` INT NULL,
PRIMARY KEY (`idPeriodoAlumno`, `Periodo_idPeriodo`, `Alumno_idAlumno`),
INDEX `fk_Periodo_has_Alumno_Alumno1_idx` (`Alumno_idAlumno` ASC),
INDEX `fk_Periodo_has_Alumno_Periodo1_idx` (`Periodo_idPeriodo` ASC),
CONSTRAINT `fk_Periodo_has_Alumno_Periodo1`
FOREIGN KEY (`Periodo_idPeriodo`)
REFERENCES `celex`.`Periodo` (`idPeriodo`)
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Periodo_has_Alumno_Alumno1`
FOREIGN KEY (`Alumno_idAlumno`)
REFERENCES `celex`.`Alumno` (`idAlumno`)
ON DELETE SET NULL
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `celex`.`Maestro`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`Maestro` (
`idMaestro` INT NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR(45) NOT NULL,
`primerApellido` VARCHAR(45) NOT NULL,
`segundoApellido` VARCHAR(45) NOT NULL,
`email` VARCHAR(45) NOT NULL,
`telefono` VARCHAR(45) NULL,
PRIMARY KEY (`idMaestro`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `celex`.`GrupoMaestro`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `celex`.`GrupoMaestro` (
`idGrupoMaestro` INT NOT NULL AUTO_INCREMENT,
`Grupo_idGrupo` INT NULL,
`Maestro_idMaestro` INT NULL,
PRIMARY KEY (`idGrupoMaestro`, `Grupo_idGrupo`, `Maestro_idMaestro`),
INDEX `fk_Grupo_has_Maestro_Maestro1_idx` (`Maestro_idMaestro` ASC),
INDEX `fk_Grupo_has_Maestro_Grupo1_idx` (`Grupo_idGrupo` ASC),
CONSTRAINT `fk_Grupo_has_Maestro_Grupo1`
FOREIGN KEY (`Grupo_idGrupo`)
REFERENCES `celex`.`Grupo` (`idGrupo`)
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Grupo_has_Maestro_Maestro1`
FOREIGN KEY (`Maestro_idMaestro`)
REFERENCES `celex`.`Maestro` (`idMaestro`)
ON DELETE SET NULL
ON UPDATE CASCADE)
ENGINE = InnoDB;
SET SQL_MODE=#OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;
edit: Appending query to create database.
When setting the Foreign Key constraint, in addition to cascade on update you can define to set null on delete like this:
FOREIGN KEY (Grupo_idGrupo) REFERENCES Grupo (idGrupo)
ON DELETE SET NULL ON UPDATE CASCADE
I am getting an error with mysql and I do not understand why:
SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
CREATE SCHEMA IF NOT EXISTS `feedback` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `feedback` ;
-- -----------------------------------------------------
-- Table `feedback`.`application`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`application` (
`application_id` INT NOT NULL AUTO_INCREMENT,
`app_name` VARCHAR(45) NULL,
PRIMARY KEY (`application_id`),
UNIQUE INDEX `app_name_UNIQUE` (`app_name` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`user` (
`user_id` INT NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(45) NOT NULL,
`lastname` VARCHAR(45) NULL,
`email` VARCHAR(45) NOT NULL,
`customer_length` VARCHAR(45) NULL,
PRIMARY KEY (`user_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`users_has_application`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`users_has_application` (
`user_id` INT NOT NULL,
`application_id` INT NOT NULL,
PRIMARY KEY (`user_id`, `application_id`),
INDEX `fk_users_has_application_application1_idx` (`application_id` ASC),
INDEX `fk_users_has_application_users_idx` (`user_id` ASC),
CONSTRAINT `fk_users_has_application_users`
FOREIGN KEY (`user_id`)
REFERENCES `feedback`.`user` (`user_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_has_application_application1`
FOREIGN KEY (`application_id`)
REFERENCES `feedback`.`application` (`application_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`survey`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`survey` (
`survey_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`description` VARCHAR(255) NULL,
`is_active` TINYINT(1) NULL,
PRIMARY KEY (`survey_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`question`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`question` (
`question_id` INT NOT NULL,
`question_text` VARCHAR(255) NULL,
PRIMARY KEY (`question_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`option`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`option` (
`option_id` INT NOT NULL AUTO_INCREMENT,
`question_id` INT NOT NULL,
`option_number` INT NOT NULL,
`option_text` TEXT NULL,
INDEX `fk_option_question1_idx` (`question_id` ASC),
PRIMARY KEY (`option_id`),
UNIQUE INDEX `uk_question_option_number_key` (`question_id` ASC, `option_number` ASC),
CONSTRAINT `fk_option_question1`
FOREIGN KEY (`question_id`)
REFERENCES `feedback`.`question` (`question_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`answer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`answer` (
`answer_id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`option_id` INT NOT NULL,
`date_submitted` DATETIME NOT NULL,
PRIMARY KEY (`answer_id`),
INDEX `fk_answer_user1_idx` (`user_id` ASC),
INDEX `fk_answer_option1_idx` (`option_id` ASC),
CONSTRAINT `fk_answer_user1`
FOREIGN KEY (`user_id`)
REFERENCES `feedback`.`user` (`user_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_answer_option1`
FOREIGN KEY (`option_id`)
REFERENCES `feedback`.`option` (`option_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `feedback`.`survey_has_question`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `feedback`.`survey_has_question` (
`survey_id` INT NOT NULL,
`question_id` INT NOT NULL,
`question_number` INT NULL,
PRIMARY KEY (`survey_id`, `question_id`),
INDEX `fk_survey_has_question_question1_idx` (`question_id` ASC),
INDEX `fk_survey_has_question_survey1_idx` (`survey_id` ASC),
UNIQUE INDEX `unique_order_key` (`survey_id` ASC, `question_number` ASC),
CONSTRAINT `fk_survey_has_question_survey1`
FOREIGN KEY (`survey_id`)
REFERENCES `feedback`.`survey` (`survey_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_survey_has_question_question1`
FOREIGN KEY (`question_id`)
REFERENCES `feedback`.`question` (`question_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=#OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;
Error:
#1005 - Can't create table 'feedback.answer' (errno: 150)
I am creating my table from this as a template:
https://dba.stackexchange.com/questions/16002/survey-database-design-associate-an-answer-to-a-user/16047#16047
My thought process for adding answer_id to the answer table is that I want users to be able to fill out the same survey multiple times.
Why is the answer table throwing an error?
EDIT:
Server version: 5.5.29-0ubuntu0.12.04.2
I am importing this using phpmyadmin
Your code worked on MYSQL server 5.1 without errors.
A common cause of errno: 150 is when you create a FK constraint that references a PK that does not yet exist. Make sure both your "user" and "option" tables are created first before you create the "answer" table.
To help debug you can remove the FK constraints one at a time to see which one is triggering the problem.
If you execute the code in the order shown, I do not see any FK problems that would occur.
try this
SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Table `feedback`.`application`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `application` (
`application_id` INT NOT NULL AUTO_INCREMENT,
`app_name` VARCHAR(45) NULL,
PRIMARY KEY (`application_id`),
UNIQUE INDEX `app_name_UNIQUE` (`app_name` ASC))
;
your working code in fiddle