Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in alter.sql #120

Open
DragonBe opened this issue Jan 2, 2015 · 1 comment
Open

Errors in alter.sql #120

DragonBe opened this issue Jan 2, 2015 · 1 comment

Comments

@DragonBe
Copy link
Contributor

DragonBe commented Jan 2, 2015

There are several errors in alter.sql that prevent users to succesfully install the database correctly.

@DragonBe
Copy link
Contributor Author

DragonBe commented Jan 2, 2015

Tried to simplify the issue in the following example:

CREATE TABLE `test`.`table1` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `field1` VARCHAR(10) NOT NULL,
    `field2` VARCHAR(10) NULL,
    `field3` TIMESTAMP NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `table1_field1_uk` (`field1`),
    UNIQUE KEY `table1_field3_uk` (`field3`)
) ENGINE=InnoDB;

CREATE TABLE `test`.`table2` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `field1` VARCHAR(10) NOT NULL,
    `field2` VARCHAR(10) NULL,
    `field3` TIMESTAMP NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `table2_field1_uk` (`field1`),
    UNIQUE KEY `table2_field3_uk` (`field3`)
) ENGINE=InnoDB;

ALTER TABLE `test`.`table1`
    ADD CONSTRAINT `fk_table1_fields` 
    FOREIGN KEY (`id`, `field1`, `field3`)
        REFERENCES `test`.`table2` (`id`, `field1`, `field3`)
            ON UPDATE CASCADE
            ON DELETE CASCADE;

This gives the following error code without any other information. It looks OK to me, but apparently I'm missing something important.

Error Code: 1215. Cannot add foreign key constraint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant