I am trying to forward my schema into a mysql database, but I cannot get it to w
ID: 3800127 • Letter: I
Question
I am trying to forward my schema into a mysql database, but I cannot get it to work. I tried multiple checklists, including the
Check List
Is Db InnoDB? Yes
Are all tables InnoDB ? Yes
Is unique index present on referencing table ? Yes
Are referenced and referencing column exactly of the same type ? Yes
This is the table, when i run it I get this error:
--------------------------------------------------------------------------------------
ERROR: Error 1215: Cannot add foreign key constraint
DROP TABLE IF EXISTS `mydb`.`warranty` ;
CREATE TABLE IF NOT EXISTS `mydb`.`warranty` (
`warranty_id` VARCHAR(255) NOT NULL,
`warranty_number` VARCHAR(25) NOT NULL COMMENT 'Warranty Number',
`warranty_effective_date` DATETIME NOT NULL COMMENT 'Warranty Effective Date',
`payment_option` VARCHAR(100) NOT NULL COMMENT 'Pay monthly or annunally, or all at once',
`total_amount` DOUBLE NOT NULL COMMENT 'Total Warranty Amount ',
`active` TINYINT(1) NOT NULL,
`date_created` DATETIME NOT NULL,
`additional_information` LONGTEXT NULL COMMENT 'Additional information for finance, and car dealership. Will not be seen by customer',
PRIMARY KEY (`warranty_id`))
ENGINE = InnoDB;
Explanation / Answer
Here is the below code for the above scenario:
CREATE TABLE IF NOT EXISTS users (
id int(11) NOT NULL,
username varchar(255) NOT NULL,
first_name varchar(255) NOT NULL,
last_name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
password varchar(32) NOT NULL,
sign_up_date date NOT NULL,
activated enum('0','1') NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.