简体   繁体   English

使用外键将数据从文本文件插入表中

[英]inserting data into table from text file with a foreign key

I have two tables, people and registration. 我有两个表,人员和注册。

people table contains - idpeople, name and email columns 人员表包含-idpeople,姓名和电子邮件列

registration table contains - idregistration, country, registered, people_idpeople 注册表包含-idregistration,国家/地区,已注册,people_idpeople

I loaded data into the first table via text file and every thing went well. 我通过文本文件将数据加载到第一个表中,一切顺利。 But when trying to add data into registration table I get "error 1452" which is a foreign key restraint. 但是,当尝试将数据添加到注册表时,出现“错误1452”,这是外键约束。

what does my text file need to look like so that I can load data into it and it relate to the people table? 我的文本文件需要什么样才能将数据加载到其中并与people表相关?

heres what the overall text data looks like, but i had to break it down for each table: 这是整体文本数据的外观,但是我不得不为每个表将其分解:

Email,Full Name,Country,Date Registered
Carley_Bahringer@destiny.com,Carley Bahringer,Papua New Guinea,1987-10-03 22:09:54 
Patricia_Fadel@avis.com,Patricia Fadel,Saint Lucia,2012-05-10 11:07:49 
Sedrick@godfrey.ca,Sedrick Kuphal,Chile,2007-11-12 00:09:53 
Briana_Berge@axel.ca,Briana Berge,Nicaragua,2006-03-26 15:32:08 
Lucy_Lockman@abby.org,Lucy Lockman,Iceland,2014-02-13 10:26:57 
Lucy_Lockman@abby.org,Lucy Lockman,Germany,1999-02-12 00:14:54 
Ayden_Flatley@colin.biz,Ayden Flatley,France,1987-01-23 21:43:22 
Alec.Boyle@aurore.co.uk,Alec Boyle,Brazil,2007-08-23 13:42:41 
Ozella_Feil@prudence.ca,Ozella Feil,Lesotho,2005-12-30 18:24:59 
Ozella_Feil@prudence.ca,Ozella Feil,Sweden,2009-06-19 10:32:55 

for the people table I edited the above info so it just contained name and email. 对于人员表,我编辑了上述信息,因此只包含姓名和电子邮件。 What do i do to load the rest of the info into registration table? 如何将其余信息加载到注册表中?

No, since you have people_idpeople as FK in Registration table; 不,因为您在Registration people_idpeople为FK; you need to provide that information as well else you will see the error you are facing currently. 您还需要提供该信息,否则您将看到当前面临的错误。 Your data should look like (Example) 您的数据应类似于(示例)

Email,Full Name,Country,Date Registered,idpeople
Carley_Bahringer@destiny.com,Carley Bahringer,Papua New Guinea,1987-10-03 22:09:54, 1

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

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