Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8982857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:41:04+00:00 2026-06-15T20:41:04+00:00

When I try loading a file of CSV data using the –local-infile option, I

  • 0

When I try loading a file of CSV data using the –local-infile option, I get the following error:

ERROR 1452 (23000) at line 2: Cannot add or update a child row: a foreign key constraint fails (realtax.city_desc, CONSTRAINT city_desc_ibfk_1 FOREIGN KEY (cityid) REFERENCES city (id) ON DELETE CASCADE ON UPDATE CASCADE)

The error happens at the first line of the CSV file (i.e., no rows get loaded at all).

Here is the actual mysql load command:

load data LOCAL infile 'out/desc.in' into table city_desc fields terminated by ',' lines terminated by '\n';

Here is the first line of the CSV file:

# head -1 out/desc.in
NULL,1000,"R4","B1","NWC125","SUNRISE ACRES #1 W 120 FT OF S 75",0.207

When I use the mysql CLI, however, I am able to load the first line without issue. Here is the result:

mysql> insert into city_desc values (NULL,1000,”R4″,”B1″,”NWC125″,”SUNRISE ACRES #1 W 120 FT OF S 75″,0.207);
Query OK, 1 row affected (0.04 sec)

Here is the line of table data to which it refers:

mysql> select * from city limit 1;
+——+———+—————–+
| id | prop_id | pidn |
+——+———+—————–+
| 1000 | 10208 | S912999001L0800 |
+——+———+—————–+
1 row in set (0.00 sec)

Here are the SQL definitions for each table:

create table if not exists city 
(
    id              INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    prop_id         int,
    pidn            varchar(100)
) AUTO_INCREMENT=1000, engine=innodb;

create table if not exists city_desc
(
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    cityid          int not null,
    zoning          varchar(20), 
    state_cd        varchar(20), 
    map_id          varchar(20), 
    legal_desc      varchar(100), 
    legal_acres     numeric(5,5),
    foreign key (cityid) references city(id)
    on update cascade on delete cascade
) AUTO_INCREMENT=500000, engine=innodb;

create index propid_city on city(prop_id);
create index pidn_city on city(pidn);

I read the other threads about turning off the referential checks using:

SET foreign_key_checks = 0;

but instead of hacking a fix, I would like to know the reason why this works manually but not with the –local-infile option. The foreign reference is there (record id 1000), so why wouldn’t it work?

UPDATE: Here is the information I received after running SHOW ENGINE INNODB STATUS right after the failed insert:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
121212 13:50:55 Transaction:
TRANSACTION 0 901853, ACTIVE 0 sec, process no 3217, OS thread id 140224990570240 inserting, thread declared inside InnoDB 492
mysql tables in use 1, locked 1
5 lock struct(s), heap size 1216, 9 row lock(s), undo log entries 9
MySQL thread id 15389, query id 1442612 localhost root
load data LOCAL infile 'out/desc.in' into table city_desc fields terminated by ',' lines terminated by '\n'
Foreign key constraint fails for table `realtax`.`city_desc`:
,
  CONSTRAINT `city_desc_ibfk_1` FOREIGN KEY (`cityid`) REFERENCES `city` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
Trying to add in child table, in index `cityid` tuple:
DATA TUPLE: 2 fields;
 0: len 4; hex 80000000; asc     ;; 1: len 4; hex 800ea15e; asc    ^;;

But in parent table `realtax`.`city`, in index `PRIMARY`,
the closest match we can find is record:
PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 4; hex 800003e8; asc     ;; 1: len 6; hex 00000007aed1; asc       ;; 2: len 7; hex 800000002d0110; asc     -  ;; 3: len 4; hex 800027e0; asc   ' ;; 4: len 15; hex 533931323939393030314c30383030; asc S912999001L0800;;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:41:05+00:00Added an answer on June 15, 2026 at 8:41 pm

    Based on the information you’ve presented, that row shouldn’t have created any problem. Therefore, quick question: how many rows are in the csv? If more than 1 row, does at least one of them contain foreign key value that isn’t in the primary key?
    If the row does indeed contain the data data, the error definitely isn’t on that row; it is on a different row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
I am using the following method for reading Csv file content: /// <summary> ///
I am getting the following error when I try loading one of my php
I have a csv log file. After loading it into Hive using this sentence:
I am loading Auto complete text view with data written in my csv file
I have a small script we're using to read in a CSV file containing
webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl(http://officeofthemufti.sg/MaulidBooklet.pdf); I am using WebView try to loading pdf
I am trying to make a contour plot of the following data using matplotlib
I want to load a csv file into R from Java using JRI. For
Im trying to read data from a text file and loading it into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.