简体   繁体   English

phpMyAdmin不根据外键导出数据库结构

[英]phpMyAdmin not exporting database structures according to foreign keys

I have a list of tables in MySQL with foreign key constraints. 我有一个带有外键约束的MySQL表列表。 While exporting, all tables along with views, functions and procedures are exported in alphabetical orders. 导出时,所有表以及视图,函数和过程均按字母顺序导出。

As I import thus exported SQL, I am stuck with the error that "Foreign key constraints table not found" though the structure of required table is below in listing. 当我导入这样导出的SQL时,尽管下面列出了所需表的结构,但我仍然遇到“找不到外键约束表”的错误。 I want to export them in order so that they maintain every references in structure. 我想按顺序导出它们,以便它们维护结构中的每个引用。

How could it be done using MySQL? 如何使用MySQL完成?

It's not possible to export tables in the order that respects "foreign keys", unless you export the tables individually. 除非您单独导出表,否则无法按照尊重“外键”的顺序导出表。 Then import the tables from the individual export in the order you want. 然后按所需顺序从单个导出中导入表。 (Note that its possible for a database to contain circular foreign key references, where there's no order that the tables would be in "foreign key" order.) (请注意,数据库可能包含循环外键引用,而表没有按“外键”顺序排序。)


(As an answer to a somewhat different question...) (作为对某些不同问题的解答...)

The workaround for the import error is to disable enforcement of foreign keys for the duration of the import process. 导入错误的解决方法是在导入过程中禁用外键的实施。 Setting the foreign_key_checks variable to 0 disables enforcement of foreign keys; foreign_key_checks变量设置为0将禁用强制执行外键; to re-enable, set the variable to 1. 要重新启用,请将变量设置为1。

For example: 例如:

SET FOREIGN_KEY_CHECKS = 0; 

-- import tables
create table ... 
insert into ...
create table ... 
insert into ...

SET FOREIGN_KEY_CHECKS = 1;  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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