E
E
entermix2015-11-09 22:17:40
MySQL
entermix, 2015-11-09 22:17:40

Why is the foreign key not being added?

There are sl. tables:
payments: pastebin.com/KMZgKdNi
payment_statuses: pastebin.com/Lu7pbj0Q
payment_types: pastebin.com/Dhq2GgQR
The payments table is currently full, type_id field == 0 (tried to put 1 - no result), when executing the request:

ALTER TABLE `payments` ADD CONSTRAINT `payments_ibfk_3` FOREIGN KEY (`type_id`) REFERENCES `db_name`.`payment_types`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;

An error occurs: "Error creating foreign key on type_id (check data types)", why so? Do you really need to remove all information from the payments table in order to add a foreign key?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-11-09
@entermix

To create a key, the `payment_types` table must have records with all `id`s that match all available `payments`.`type_id`.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question