1

我有以下 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;

并且 ALTER TABLE tagged_face 命令失败并出现奇怪的“无法创建表错误 150”错误。

我查看了有关此问题的其他帖子,但我没有看到我做错了什么(外键引用相同类型且唯一的列)。有人有想法么?

谢谢

4

2 回答 2

3

您的face_image表没有索引。需要一个索引来监管FOREIGN KEY约束。

在表上添加一个索引face_image,你应该设置...

于 2013-06-05T21:19:16.447 回答
1

我认为这一切都失败了:

REFERENCES feature(id)

也许你必须参考:

REFERENCES grouped_feature(id)

或者

REFERENCES tweaked_feature(id)

在我的本地 mysql 数据库上测试。

于 2013-06-05T21:17:21.583 回答