I have the following SQL:
CREATE TABLE face_group (id BIGINT AUTO_INCREMENT, name VARCHAR(100), description VARCHAR(200), pivotxpos FLOAT(18, 2) NOT NULL, pivotypos FLOAT(18, 2) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE face_image (id bigint NOT NULL, imageurl VARCHAR(200) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL) ENGINE = INNODB;
CREATE TABLE face_tag (id bigint NOT NULL, name VARCHAR(100), tagtype VARCHAR(100), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL) ENGINE = INNODB;
CREATE TABLE grouped_feature (id BIGINT AUTO_INCREMENT, name VARCHAR(100) NOT NULL, feature_id bigint NOT NULL, face_group_id bigint NOT NULL, pivotxposoverride FLOAT(18, 2) NOT NULL, pivotyposoverride FLOAT(18, 2) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX face_group_id_idx (face_group_id), INDEX feature_id_idx (feature_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE tagged_face (id bigint NOT NULL, face_image_id bigint NOT NULL, face_tag_id bigint NOT NULL, tag_value VARCHAR(100), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX face_image_id_idx (face_image_id), INDEX face_tag_id_idx (face_tag_id)) ENGINE = INNODB;
CREATE TABLE tweaked_curve (id BIGINT AUTO_INCREMENT, tweaked_feature_id bigint NOT NULL, curve_id bigint NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX tweaked_feature_id_idx (tweaked_feature_id), INDEX curve_id_idx (curve_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE tweaked_feature (id BIGINT AUTO_INCREMENT, face_group_id bigint NOT NULL, feature_id bigint NOT NULL, face_image_id bigint NOT NULL, pivotxpos FLOAT(18, 2) NOT NULL, pivotypos FLOAT(18, 2) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX face_group_id_idx (face_group_id), INDEX feature_id_idx (feature_id), INDEX face_image_id_idx (face_image_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE tweaked_point (id BIGINT AUTO_INCREMENT, tweaked_curve_id bigint NOT NULL, point_id bigint NOT NULL, xposoverride FLOAT(18, 2) NOT NULL, yposoverride FLOAT(18, 2) NOT NULL, user_tweaked TINYINT(1) DEFAULT '0' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX tweaked_curve_id_idx (tweaked_curve_id), INDEX point_id_idx (point_id), PRIMARY KEY(id)) ENGINE = INNODB;
ALTER TABLE grouped_feature ADD CONSTRAINT grouped_feature_feature_id_feature_id FOREIGN KEY (feature_id) REFERENCES feature(id) ON DELETE CASCADE;
ALTER TABLE grouped_feature ADD CONSTRAINT grouped_feature_face_group_id_face_group_id FOREIGN KEY (face_group_id) REFERENCES face_group(id) ON DELETE CASCADE;
ALTER TABLE tagged_face ADD CONSTRAINT tagged_face_face_tag_id_face_tag_id FOREIGN KEY (face_tag_id) REFERENCES face_tag(id) ON DELETE CASCADE;
ALTER TABLE tagged_face ADD CONSTRAINT tagged_face_face_image_id_face_image_id FOREIGN KEY (face_image_id) REFERENCES face_image(id) ON DELETE CASCADE;
ALTER TABLE tweaked_curve ADD CONSTRAINT tweaked_curve_tweaked_feature_id_tweaked_feature_id FOREIGN KEY (tweaked_feature_id) REFERENCES tweaked_feature(id) ON DELETE CASCADE;
ALTER TABLE tweaked_curve ADD CONSTRAINT tweaked_curve_curve_id_curve_id FOREIGN KEY (curve_id) REFERENCES curve(id) ON DELETE CASCADE;
ALTER TABLE tweaked_feature ADD CONSTRAINT tweaked_feature_feature_id_feature_id FOREIGN KEY (feature_id) REFERENCES feature(id) ON DELETE CASCADE;
ALTER TABLE tweaked_feature ADD CONSTRAINT tweaked_feature_face_image_id_face_image_id FOREIGN KEY (face_image_id) REFERENCES face_image(id) ON DELETE CASCADE;
ALTER TABLE tweaked_feature ADD CONSTRAINT tweaked_feature_face_group_id_face_group_id FOREIGN KEY (face_group_id) REFERENCES face_group(id) ON DELETE CASCADE;
ALTER TABLE tweaked_point ADD CONSTRAINT tweaked_point_tweaked_curve_id_tweaked_curve_id FOREIGN KEY (tweaked_curve_id) REFERENCES tweaked_curve(id) ON DELETE CASCADE;
ALTER TABLE tweaked_point ADD CONSTRAINT tweaked_point_point_id_point_id FOREIGN KEY (point_id) REFERENCES point(id) ON DELETE CASCADE;
And the ALTER TABLE tagged_face command fails with a strange "can't create table error 150" error.
I've looked at other posts regarding this issue but I don't see what I'm doing wrong (foreign keys reference columns of the same type and that are unique). Anyone have any ideas?
Thanks
Your face_image
table has no index. An index is required to police the FOREIGN KEY
constraint.
Add an index on the face_image
table and you should be set ...
I think it all fails here:
REFERENCES feature(id)
Maybe you have to reference to:
REFERENCES grouped_feature(id)
Or
REFERENCES tweaked_feature(id)
Tested on my local mysql database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.