将 MyISAM 键插入 INNODB 表
我将这个表结构用于“toxi”之类的标签系统,
table TAGS
+--------+-------------------+
| alias | isactive | varchar(55), tinyint(1)
+--------+-------------------+
| party | 1 |
Engine: MyISAM (because I use some 'autocomplete' using this table (field:alias) for
a %xxx% search
table TAGREL
+-------------+-------------------+
| tags_alias | productID | varchar(55), int(11)
+-------------+-------------------+
| party | 15 |
Engine: InnoDB (i dont need full search here)
This TAGREL table uses tags.alias as FK (on update cascade, on delete cascade) and
product id as FK (on update no action, on delete cascade)
我的意思是,整个想法是,当我更新某些标签名称(或删除它)甚至删除产品时,TAGREL 上的关系会自动更新。
但我什至无法向 TAGREL 表添加一条记录,它说表 TAGS 上的外键错误,即使我插入的数据是正确的(有效的 TAGS 别名和有效的产品 ID)
我也不能这样做MySQL 上的东西? 唯一的解决方案(因为我需要在标签表上进行完整搜索)是每当我更新某些标签或删除产品时手动更新 tagrel ?
谢谢。
I'm using this table structure for a 'toxi' like TAGs system
table TAGS
+--------+-------------------+
| alias | isactive | varchar(55), tinyint(1)
+--------+-------------------+
| party | 1 |
Engine: MyISAM (because I use some 'autocomplete' using this table (field:alias) for
a %xxx% search
table TAGREL
+-------------+-------------------+
| tags_alias | productID | varchar(55), int(11)
+-------------+-------------------+
| party | 15 |
Engine: InnoDB (i dont need full search here)
This TAGREL table uses tags.alias as FK (on update cascade, on delete cascade) and
product id as FK (on update no action, on delete cascade)
I mean, the whole idea is that, when I update some tag name (or erase it) or even delete a product, the relation on the TAGREL is auto updated.
But I cant even ADD a record to TAGREL table, it says a foreign key on table TAGS error, even if the data I'm inserting is correct (a valid TAGS alias and a valid product ID)
I can't do this kind of thing on MySQL?
The only solution (as I NEED the full search on the TAGS table) is to manually update the tagrel whenever I update some tag OR erase a product?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在引用
MyISAM
表的InnoDB
表中创建外键。http://dev.mysql.com/doc /refman/5.0/en/innodb-foreign-key-constraints.html
所以,是的,如果您不更改存储引擎,您将必须手动强制应用程序代码中的约束。
LIKE '%XXX%'
搜索不是全文;除非您实际指定了全文索引并使用全文匹配功能,否则不需要使用 MyISAM 引擎。You cannot create foreign keys in
InnoDB
tables referencingMyISAM
tables.http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html
So yes, you will have to manually enforce the constraints from your application code if you do not change the storage engine.
LIKE '%XXX%'
searches are not fulltext; unless you actually specified a fulltext index and are using fulltext matching functions, you do not need to use the MyISAM engine.