出于某种原因,我的Django web应用程序中的MySQL表使用不同的格式,这会导致外键约束错误(如this question)。
下面是表格格式的样子。

SHOW TABLE STATUS WHERE `Name` in ('') ...
+----------------------------+--------+---------+------------+--------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------
| Name                       | Engine | Version | Row_format | Rows   | Avg_row_length | Data_length | Max_data_length  | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time
+----------------------------+--------+---------+------------+--------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------
| table_0                    | MyISAM |      10 | Dynamic    |    341 |             83 |       28472 |  281474976710655 |        19456 |         0 |            346 | 2013-09-05 15:52:11 | 2014-01-10 14:17:18 | 2013-09-05 15:52:11
| table_1                    | MyISAM |      10 | Dynamic    |  66422 |             49 |     3297260 |  281474976710655 |      2025472 |         0 |         141146 | 2013-07-20 19:12:24 | 2014-01-10 19:20:21 | 2013-07-20 19:12:27
| table_2                    | MyISAM |      10 | Dynamic    |      3 |             53 |         160 |  281474976710655 |         3072 |         0 |              4 | 2013-07-20 19:12:27 | 2013-07-20 19:12:27 | 2013-07-20 19:12:27
| table_3                    | MyISAM |      10 | Dynamic    |      8 |             99 |         796 |  281474976710655 |         3072 |         0 |             10 | 2013-07-20 19:12:27 | 2013-07-20 19:12:27 | 2013-07-20 19:12:27
| table_4                    | MyISAM |      10 | Dynamic    |      0 |              0 |           0 |  281474976710655 |         1024 |         0 |              1 | 2013-07-20 19:12:27 | 2013-07-20 19:12:27 | 2013-07-20 19:12:27
| table_5                    | InnoDB |      10 | Compact    |      0 |              0 |       16384 |                0 |        16384 |   7340032 |              1 | 2013-11-20 14:04:02 | NULL                | NULL
| table_6                    | InnoDB |      10 | Compact    |      0 |              0 |       16384 |                0 |        16384 |   7340032 |              1 | 2013-11-20 14:03:39 | NULL                | NULL
| table_7                    | MyISAM |      10 | Dynamic    |    860 |            125 |      107624 |  281474976710655 |        25600 |         0 |            977 | 2013-11-20 14:04:35 | 2014-01-06 18:32:57 | 2013-11-20 14:04:35
| table_8                    | MyISAM |      10 | Fixed      |   6632 |             21 |      139272 | 5910974510923775 |       173056 |         0 |           6753 | 2013-07-20 19:16:47 | 2014-01-09 11:26:36 | 2013-07-20 19:16:47

我试图更新this question中描述的表格格式。但收到以下错误。
mysql> SET FOREIGN_KEY_CHECKS=0;
mysql> alter table ztrap_emailreportoptin engine = MyISAM;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

我怎样才能使发动机在两个表之间保持一致?
(还有,你知道这是怎么开始的吗?)

最佳答案

MyISAM does not support foreign keys
若要转换为MyISAM,需要先删除所有外键约束。
错误消息告诉您表ztrap_emailreportoptin引用了另一个表,或者被另一个表引用。
您可以列出此类参考:

SELECT
    table_name, column_name, constraint_name,
    referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE referenced_table_name IS NOT NULL;

但是,我建议将表转换成InnoDB。

关于python - 将表从InnoDB转换为MyISAM时,“外键约束失败”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21055466/

10-13 07:30