无法在mysql中创建外键约束

时间:2020-02-26 07:09:22

标签: mysql phpmyadmin

我无法在mysql中为“ vsa”列创建外键约束,以下是我的表结构。我收到错误提示为“在vsa(检查数据类型)上创建外键时出错”。在这里,我看不到数据类型的任何问题。我想念什么。

CREATE TABLE `child` ( `id` int(11) NOT NULL, `day` tinyint(3) NOT NULL, `vsa` varchar(50) NOT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `parent` ( `price_id` int(10) NOT NULL, `device_id` text NOT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `vsa` varchar(50) NOT NULL, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

作为一种替代方法,我运行alter查询来添加约束。我正在错误以下。

Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html
for correct foreign key definition. ```

0 个答案:

没有答案