简体   繁体   中英

Insert MyISAM key into a INNODB table

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.

You cannot create foreign keys in InnoDB tables referencing MyISAM tables.

Foreign keys definitions are subject to the following conditions:

Both tables must be InnoDB tables and they must not be TEMPORARY 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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM