Why my table doesnt support FOREIGN KEYS?

后端 未结 5 1292
盖世英雄少女心
盖世英雄少女心 2020-12-11 10:40

I have made a database and 10 tables in mysql(table type NONE) and i can\'t create foreign keys. An alert message says

SQLyog The selected table does not support for

相关标签:
5条回答
  • 2020-12-11 10:42

    Typically, InnoDB is used to support foreign keys, and transactions:

    http://dev.mysql.com/doc/refman/5.1/en/innodb.html

    You can change the table engine on the fly:

    ALTER TABLE tableName ENGINE = InnoDB;
    

    You can also change the default -- for newly created tables -- as shown here:

    http://dev.mysql.com/doc/refman/5.1/en/storage-engine-setting.html

    0 讨论(0)
  • 2020-12-11 10:59

    The engine you're using doesn't support foreign keys (as the error message tells you obviously). You can change the engine you're using with

    ALTER TABLE `tableName` ENGINE = newEngine;
    
    0 讨论(0)
  • 2020-12-11 11:00

    Yes. The default storage engine (MyISAM) does not support foreign key constraints.

    0 讨论(0)
  • 2020-12-11 11:02

    I was having same problem until I found this post.

    For addressing the limitation of MyISAM or NDB (Cluster), constraints can be enforced using triggers.

    0 讨论(0)
  • 2020-12-11 11:07

    The MyISAM engine DOES support foreign keys. What it doesn't support is foreign key constraints.

    You can go ahead and create as many foreign keys as you like - but don't expect the database to enforce integrity for you.

    Don't change engines in your application without significant testing; changing engine will affect behaviour and is not recommended without great care and a lot of QA work. In particular, switching from MyISAM to InnoDB will break your application if:

    • It doesn't handle deadlocks appropriately (Deadlocks do not happen on MyISAM)
    • It expects table-level locking
    • It relies on (mostly dubious) MyISAM features
    • It is high performance and you have not understood how to tune InnoDB correctly, but did tune MyISAM well (or ok)
    • You have not assessed the disc space impact of switching engines
    0 讨论(0)
提交回复
热议问题