CREATE TABLE IF NOT EXISTS `project_flight`.`tickets` (
`flight_name` VARCHAR(50) NOT NULL,
`first_name` VARCHAR(50) NOT NULL,
`flight_number` VARCHAR(50) NOT NULL,
`ticket_number` VARCHAR(50) NOT NULL,
`price` DECIMAL(5,2) NOT NULL,
`confirmation_number` VARCHAR(250) NOT NULL,
INDEX `fk_tickets_flight_classes_idx` (`flight_name` ASC) VISIBLE,
INDEX `fk_tickets_passenger1_idx` (`first_name` ASC) VISIBLE,
PRIMARY KEY (`flight_number`, `first_name`, `flight_name`),
INDEX `fk_tickets_flight1_idx` (`flight_number` ASC) VISIBLE,
CONSTRAINT `fk_tickets_flight_classes`
FOREIGN KEY (`flight_name`)
REFERENCES `project_flight`.`flight_classes` (`name`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_tickets_passenger`
FOREIGN KEY (`first_name`)
REFERENCES `project_flight`.`passenger` (`first_name`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_tickets_flight`
FOREIGN KEY (`flight_number`)
REFERENCES `project_flight`.`flight` (`number`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB
No I can’t, it’s best I use a customer id instead, I should’ve thought of that earlier.
Though after inserting customer_id I have new problem. It says I have "Error 3734: Failed to add the foreign key constraint. Missing column ‘customer_id’ for constraint ‘fk_tickets_passenger’ in the referenced table ‘passenger’ ". And it doesn’t make any sense because if you look at my screen shot, I do have customer_id as a column for the constraint.
Executing SQL script in server
ERROR: Error 3734: Failed to add the foreign key constraint. Missing column ‘customer_id’ for constraint ‘fk_tickets_passenger’ in the referenced table ‘passenger’
SQL Code:
– -----------------------------------------------------
– Table project_flight.tickets
– -----------------------------------------------------
CREATE TABLE IF NOT EXISTS project_flight.tickets ( flight_name VARCHAR(50) NOT NULL, ticketscol VARCHAR(45) NOT NULL, customer_id VARCHAR(50) NOT NULL, ticket_number VARCHAR(50) NOT NULL, price DECIMAL(5,2) NOT NULL, confirmation_number VARCHAR(250) NOT NULL, flight_air_line VARCHAR(50) NOT NULL,
INDEX fk_tickets_flight_classes_idx (flight_name ASC) VISIBLE,
PRIMARY KEY (flight_name, ticketscol, flight_air_line),
INDEX fk_tickets_passenger_idx (customer_id ASC) VISIBLE,
INDEX fk_tickets_flight_idx (flight_air_line ASC) VISIBLE,
CONSTRAINT fk_tickets_flight_classes
FOREIGN KEY (flight_name)
REFERENCES project_flight.flight_classes (name)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT fk_tickets_passenger
FOREIGN KEY (customer_id)
REFERENCES project_flight.passenger (customer_id)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT fk_tickets_flight1
FOREIGN KEY (flight_air_line)
REFERENCES project_flight.flight (air_line)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB