开发者

mysql export sql dump alphabatically,which cause foreign key constraints error during import

开发者 https://www.devze.com 2022-12-25 00:25 出处:网络
I have 10 tables in my database(MySQL). two of them is given below tbl_state state_id|int(10)|UNSIGNED ZEROFILLauto_increment

I have 10 tables in my database(MySQL). two of them is given below

tbl_state

state_id    |int(10)  |UNSIGNED ZEROFILL  auto_increment 
state_name  |varchar(40) 

tbl_city

city_id     |int(10)  |UNSIGNED ZEROFILL  auto_increment 
city_name   |varchar(40) |
state_code  |int(10)  | UNSIGNED ZEROFILL (FK reference with tbl_state.state_id)

Foreign Key Constraint : tbl_city.state_code is references to tbl_state.state_id .

now my problem is

when I export all tables and import again then it gives

foreign key constraint fails error.... because when I export mysql dump, sql dump is generated in alphabetically ordered tables and tbl_city comes before tbl_state in database.

Please suggest me how do I handle this scenario?

Is there any way开发者_如何学JAVA that all tables comes in the order of foreign key references?


You want to disable foreign key checks at start of the dump, and then enable them after all the data is dumped:

SET FOREIGN_KEY_CHECKS=0

... dump ...

SET FOREIGN_KEY_CHECKS=1


By any chance if you use SQLYog. Use this property.

mysql export sql dump alphabatically,which cause foreign key constraints error during import

0

精彩评论

暂无评论...
验证码 换一张
取 消