Answer the question
In order to leave comments, you need to log in
Why don't you want to create a table?
CREATE TABLE IF NOT EXISTS `offers_representative` (
`offers_representative_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`customers_id` INT NOT NULL,
`products_id` INT NOT NULL,
`products_price` DECIMAL( 14, 6 ) NOT NULL,
FOREIGN KEY(customers_id) REFERENCES customers(customers_id),
FOREIGN KEY(products_id) REFERENCES products(products_id)
) ENGINE=InnoDB;
#1005 - Can't create table 'project.offers_representative' (errno: 150)
Answer the question
In order to leave comments, you need to log in
CREATE TABLE IF NOT EXISTS `offers_representative` (
`offers_representative_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`customers_id` INT NOT NULL,
`products_id` INT NOT NULL,
`products_price` DECIMAL( 14, 6 ) NOT NULL,
CONSTRAINT `offers_representative_ibfk_1` FOREIGN KEY(`customers_id`) REFERENCES `customers` (`customers_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `offers_representative_ibfk_2` FOREIGN KEY(`products_id`) REFERENCES `products` (`products_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
The details of why the foreign key could not be hung can be found in a "logical and obvious" place: in the output of the SHOW ENGINE INNODB STATUS command, there is a piece of text LATEST FOREIGN KEY ERROR.
Common mistakes are int field in one table, unsigned int in another. These are different, incompatible types, aha.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question