0

为什么在表'user_individual'表中添加名为'profile_id'的外键后导入数据库时​​遇到这个问题“#1072 - 表中不存在键列'profile_id'?

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 27, 2013 at 05:48 AM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `event_management`
--

-- --------------------------------------------------------

--
-- Table structure for table `profile_company`
--

CREATE TABLE IF NOT EXISTS `profile_company` (
  `profile_id` varchar(250) NOT NULL,
  `name_business_profile` varchar(250) NOT NULL,
  `day` varchar(250) NOT NULL,
  `month` varchar(250) NOT NULL,
  `year` varchar(250) NOT NULL,
  `nationality` varchar(250) NOT NULL,
  `business_id` varchar(250) NOT NULL,
  `house_no` varchar(250) NOT NULL,
  `road_no` varchar(250) NOT NULL,
  `area_name` varchar(250) NOT NULL,
  `area_code` varchar(250) NOT NULL,
  `district` varchar(250) NOT NULL,
  `division` varchar(250) NOT NULL,
  `country` varchar(250) NOT NULL,
  `country_code` varchar(250) NOT NULL,
  `time_zone` varchar(250) NOT NULL,
  `phone_office` varchar(250) NOT NULL,
  `phone_outlet` varchar(250) NOT NULL,
  `phone_mobile` varchar(250) NOT NULL,
  `other_email_1` varchar(250) NOT NULL,
  `other_email_2` varchar(250) NOT NULL,
  `other_email_3` varchar(250) NOT NULL,
  `website_1` varchar(250) NOT NULL,
  `website_2` varchar(250) NOT NULL,
  `website_3` varchar(250) NOT NULL,
  `organization_1` varchar(250) NOT NULL,
  `organization_2` varchar(250) NOT NULL,
  `organization_3` varchar(250) NOT NULL,
  `nonprofit_1` varchar(250) NOT NULL,
  `nonprofit_2` varchar(250) NOT NULL,
  `nonprofit_3` varchar(250) NOT NULL,
  `currency_1` varchar(250) NOT NULL,
  `currency_2` varchar(250) NOT NULL,
  `currency_3` varchar(250) NOT NULL,
  `security_code_1` varchar(250) NOT NULL,
  `security_code_2` varchar(250) NOT NULL,
  `security_code_3` varchar(250) NOT NULL,
  `logo` varchar(250) NOT NULL,
  PRIMARY KEY (`profile_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `profile_company`
--


-- --------------------------------------------------------

--
-- Table structure for table `profile_individual`
--

CREATE TABLE IF NOT EXISTS `profile_individual` (
  `profile_id` varchar(250) NOT NULL,
  `name_business_profile` varchar(250) NOT NULL,
  `gender` varchar(250) NOT NULL,
  `day` varchar(250) NOT NULL,
  `month` varchar(250) NOT NULL,
  `year` varchar(250) NOT NULL,
  `regilion` varchar(250) NOT NULL,
  `nationality` varchar(250) NOT NULL,
  `national_id` varchar(250) NOT NULL,
  `business_id` varchar(250) NOT NULL,
  `house_no` varchar(250) NOT NULL,
  `road_no` varchar(250) NOT NULL,
  `area_name` varchar(250) NOT NULL,
  `area_code` varchar(250) NOT NULL,
  `district` varchar(250) NOT NULL,
  `division` varchar(250) NOT NULL,
  `country` varchar(250) NOT NULL,
  `country_code` varchar(250) NOT NULL,
  `time_zone` varchar(250) NOT NULL,
  `phone_office` varchar(250) NOT NULL,
  `phone_home` varchar(250) NOT NULL,
  `phone_mobile` varchar(250) NOT NULL,
  `other_email_1` varchar(250) NOT NULL,
  `other_email_2` varchar(250) NOT NULL,
  `other_email_3` varchar(250) NOT NULL,
  `website_1` varchar(250) NOT NULL,
  `website_2` varchar(250) NOT NULL,
  `website_3` varchar(250) NOT NULL,
  `organization_1` varchar(250) NOT NULL,
  `organization_2` varchar(250) NOT NULL,
  `organization_3` varchar(250) NOT NULL,
  `nonprofit_1` varchar(250) NOT NULL,
  `nonprofit_2` varchar(250) NOT NULL,
  `nonprofit_3` varchar(250) NOT NULL,
  `currency` varchar(250) NOT NULL,
  `security_code_1` varchar(250) NOT NULL,
  `security_code_2` varchar(250) NOT NULL,
  `security_code_3` varchar(250) NOT NULL,
  `image` varchar(250) NOT NULL,
  PRIMARY KEY (`profile_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `profile_individual`
--

INSERT INTO `profile_individual` (`profile_id`, `name_business_profile`, `gender`, `day`, `month`, `year`, `regilion`, `nationality`, `national_id`, `business_id`, `house_no`, `road_no`, `area_name`, `area_code`, `district`, `division`, `country`, `country_code`, `time_zone`, `phone_office`, `phone_home`, `phone_mobile`, `other_email_1`, `other_email_2`, `other_email_3`, `website_1`, `website_2`, `website_3`, `organization_1`, `organization_2`, `organization_3`, `nonprofit_1`, `nonprofit_2`, `nonprofit_3`, `currency`, `security_code_1`, `security_code_2`, `security_code_3`, `image`) VALUES
('C091219', 'Illeens Event Solution', 'female', '4', '11', '1990', 'Islam', 'Bangladeshi', 'N12345', 'B67890', '59', '1', 'Jamal Khan', '8420', 'Chittagong', 'Chittagong', 'Bangladesh', '50', '(GMT +6:00) Almaty, Dhaka, Colombo', '01819300331', '01617766640', '01670303979', 'illeen@yahoo.com', 'illeen@gmail.com', 'illeen@hotmail.com', 'None', 'None', 'None', 'Illeens Boutique', 'None', 'None', 'None', 'None', 'None', 'Taka', '12345', '67890', '77777', 'Illeen.jpg'),
('C091222', 'Event Solution By Mahin', 'female', '27', '10', '1989', 'Islam', 'Bangladeshi', 'N67890', 'B12345', '48', '1', 'Jamal Khan', '8421', 'Chittagong', 'Chittagong', 'Bangladesh', '50', '6', '01813456789', 'None', 'None', 'mahin@live.com', 'None', 'None', 'www.facebook.com/mahin', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'Taka', 'abcde', 'efghi', 'ijklm', 'Mahin.jpg');

-- --------------------------------------------------------

--
-- Table structure for table `user_company`
--

CREATE TABLE IF NOT EXISTS `user_company` (
  `company_name` text NOT NULL,
  `email_address` varchar(100) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `user_name` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL,
  PRIMARY KEY (`email_address`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `user_company`
--

INSERT INTO `user_company` (`company_name`, `email_address`, `phone`, `user_name`, `password`) VALUES
('Ctg Events', 'ctgevents@yahoo.com', '+8801234567890', '58eef294b54847752782276ffad32967', '58eef294b54847752782276ffad32967'),
('Cliczo Photography', 'cliczo@yahoo.com', '+8801345762398', '67ebd15ec49280cb32f627178e16c0e2', '67ebd15ec49280cb32f627178e16c0e2'),
('Suhanas Mehendi', 'suhana@yahoo.com', '+88031631234', 'a356446b79ecda0ad10c339db195262e', 'a356446b79ecda0ad10c339db195262e');

-- --------------------------------------------------------

--
-- Table structure for table `user_individual`
--

CREATE TABLE IF NOT EXISTS `user_individual` (
  `first_name` varchar(100) NOT NULL,
  `last_name` varchar(100) NOT NULL,
  `email_address` varchar(100) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `user_name` varchar(100) NOT NULL,  
  `password` varchar(100) NOT NULL,
  PRIMARY KEY (`email_address`),
  KEY `profile_id`(`profile_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `user_individual`
--

INSERT INTO `user_individual` (`first_name`, `last_name`, `email_address`, `phone`, `user_name`, `password`) VALUES
('Ajfar', 'Illeen', 'illeen@live.com', '+8801670303979', '44aee4495409c9c85f665c448df2575b', '44aee4495409c9c85f665c448df2575b'),
('Ajfar', 'Illeen', 'illeen@yahoo.com', '+8801670303979', '44aee4495409c9c85f665c448df2575b', '44aee4495409c9c85f665c448df2575b'),
('Mahin', 'Islam', 'mahin@yahoo.com', '+8801671804138', '74d5ee8d9e9c1659bf3ee0c3b9838adb', '74d5ee8d9e9c1659bf3ee0c3b9838adb');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
4

1 回答 1

0

您需要使用正确的语法来定义 FK 约束。

假设user_individual引用profile_individual您的陈述应该看起来像

CREATE TABLE IF NOT EXISTS `user_individual` (
  `first_name` varchar(100) NOT NULL,
  `last_name` varchar(100) NOT NULL,
  `email_address` varchar(100) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `user_name` varchar(100) NOT NULL,  
  `password` varchar(100) NOT NULL,
  `profile_id` varchar(250) NOT NULL, -- < you have to have an FK column
  PRIMARY KEY (`email_address`),  
  CONSTRAINT FOREIGN KEY fk_profile_id (`profile_id`) 
  REFERENCES profile_individual(`profile_id`) -- < you have to define an FK constraint that references to PK
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

这是SQLFiddle演示。

于 2013-06-27T06:39:56.727 回答