简体   繁体   English

错误-在phpmyadmin中导入.sql文件时

[英]Error- When importing .sql file in phpmyadmin

I have a .sql file which is created with MySQL Workbench .I have done Export file from Workbench to .sql .But when i try to import this .sql file in localhost/phpmyadmin its showing an error. 我有一个用MySQL Workbench创建的.sql文件。我已经完成了将文件从Workbench导出到.sql的操作 。但是,当我尝试在localhost / phpmyadmin中导入此.sql文件时,它显示了错误。

1005 - Can't create table amarjobs . amarjobs无法创建表格amarjobs profiles (errno: 150 "Foreign key constraint is incorrectly formed") profiles (错误号:150“外键约束格式不正确”)

This is profiles table: 这是profiles表:

-- Table `amarjobs`.`profiles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `amarjobs`.`profiles` (
  `id` INT NOT NULL AUTO_INCREMENT COMMENT 'job seeker\'s profile table',
  `userID` INT NULL,
  `firstName` VARCHAR(45) NULL,
  `lastName` VARCHAR(45) NULL,
  `middleName` VARCHAR(45) NULL,
  `DOB` DATE NULL,
  `gender` ENUM('M','F','Other') NULL,
  `featuredProfile` ENUM('Y','N') NULL DEFAULT 'N',
  `email` VARCHAR(100) NULL,
  `phone` VARCHAR(50) NULL,
  `summary` VARCHAR(500) NULL,
  `profilePic` VARCHAR(32) NULL,
  `created_at` TIMESTAMP NULL,
  `updated_at` TIMESTAMP NULL,
  PRIMARY KEY (`id`),
  INDEX `fkProfilesUserID_idx` (`userID` ASC),
  CONSTRAINT `fkProfilesUserID`
    FOREIGN KEY (`userID`)
    REFERENCES `amarjobs`.`users` (`id`)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
ENGINE = InnoDB;

Some table was imported but why profiles table is not imported? 导入了一些表,但是为什么不导入profiles表? Could you tell me where is the problem? 你能告诉我问题出在哪里吗?

Assuming you are importing data from some other server. 假设您正在从其他服务器导入数据。 so there should not be issues related with foreign key creation... 因此应该不存在与外键创建相关的问题...

First import its parent table users table then you can import this table. 首先导入其父表users表,然后可以导入该表。 This is the clean way. 这是干净的方法。

Other wise you can forcefully import after setting foreign_key_checks disable. 否则,您可以在将foreign_key_checks设置为disable后强制导入。 But you should not do it and use clean way. 但是您不应该这样做并且使用干净的方法。

Update: 更新:

You can get all related tables by this query: 您可以通过此查询获取所有相关表:

SELECT table_name AS 'My_Table',REFERENCED_TABLE_NAME AS 'Parent_Table' FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA ='pass_your_db_here' AND table_name in ('table1','table2',.....'tablen') AND REFERENCED_TABLE_NAME IS NOT NULL;

above query will provide all parents tables for your all tables in parent_table columnd so get unique tables from my_table & parent_table list and take backup of these tables from source server and restore on target server. 上面的查询将为您在parent_table中的所有表提供所有父表,并在my_table和parent_table列表中获取唯一表,并从源服务器备份这些表并在目标服务器上还原。

You should make (id) a primary key in amarjobs . 您应该将(id)作为amarjobs的主键。 users table. users表。

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

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