import database phpmyadmin

2019-08-04 08:31发布

问题:

I have been given an export of a database but when ever i import i get an error that i believe is because foreign keys exist in the database

SQL query:

--
-- Constraints for dumped tables
--
--
-- Constraints for table `instance`
--
ALTER TABLE  `instance` ADD CONSTRAINT  `instance_ibfk_2` FOREIGN KEY (  `user_id` ) REFERENCES  `user` (  `id` ) ,
ADD CONSTRAINT  `instance_ibfk_1` FOREIGN KEY (  `cat_id` ) REFERENCES  `category` (  `cat_id` ) ;


MySQL said: 

#1005 - Can't create table 'dalejc.#sql-152c_243' (errno: 150) 

回答1:

Try loading it into a fresh database. If it doesn't work, then you need to get the missing SQL. If it does, then you'll have to go through the file and pull out the parts you're missing.



回答2:

Looks to me like one of your KEY fields does not match.

In particular, check for UNSIGNEDness of integer fields, whose defaults may vary across installations.

Inspiration: google search for mysql errno 150



回答3:

Your guess is probably right. Try getting a detailed error message as suggested at http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

Similarly, if an ALTER TABLE fails and it refers to error 150, that means a foreign key definition would be incorrectly formed for the altered table. You can use SHOW ENGINE INNODB STATUS to display a detailed explanation of the most recent InnoDB foreign key error in the server.