简体   繁体   中英

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

registration table contains - idregistration, country, registered, 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.

what does my text file need to look like so that I can load data into it and it relate to the people table?

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; 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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