Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 05-03-2011, 04:12 PM   #1
Registered: Mar 2003
Location: Northern Virginia
Distribution: RH Enterprise, Fedora
Posts: 96

Rep: Reputation: 17
MySQL - Foreign key failure - but the problem is with Eclipse, I think...

I have created a database with 2 tables (actually 13 tables, but only 2 are involved with this..) One table contains a foreign key reference to the second table.

When I originally created the tables, I had a typo in the foreign key line. So instead of:

CONSTRAINT `dev_id` FOREIGN KEY (`dev_type`) REFERENCES `dev_type` (`id`)

I had

CONSTRAINT `dev_id` FOREIGN KEY (`dev_type`) REFERENCES `rrd_dev_type` (`id`)

So when I tried to insert a record into the first table, I got an error like:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails ("vrsn_rrd"."rrd_info", CONSTRAINT "dev_id" FOREIGN KEY ("dev_type") REFERENCES "rrd_dev_type" ("id"))

So I fixed the typo, dropped the database, recreated the database and now from the command line, I can insert records. HOWEVER, I am working with a java program built with Eclipse to read my input and load this table, and when the program runs, I get the same foreign key error. I have deleted the program war file, deleted the project from Eclipse and recreated it, deleted the database again and rebuilt it, and I can't get the program to load my data.

I am completely inexperienced with Eclipse - I'm assuming it has cached something somewhere, but I can't find it. The fact that I can load a record from the mysql command line tells me the database is now ok.

Can someone give me a hint as to how to get rid of this problem? I am building the code using Eclipse and the Vaadin development environment.

Thanks very much,

Old 05-04-2011, 07:43 AM   #2
Registered: Mar 2003
Location: Northern Virginia
Distribution: RH Enterprise, Fedora
Posts: 96

Original Poster
Rep: Reputation: 17
Problem solved...

It was a very long Monday... My apologies. There was a typo in my config file, and I was actually attempting to access the database on a test machine which didn't get the typo fixed instead of the box where I did update the database...
So the problem was simply the database itself. Sorry about that...

Old 05-04-2011, 09:00 AM   #3
Senior Member
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 779Reputation: 779Reputation: 779Reputation: 779Reputation: 779Reputation: 779Reputation: 779
Thank you for the follow up posting. I read your initial post yesterday and really didn't have a clue as to what to suggest. In hind sight, the problem and solution both make perfect sense. I ran into a similar situation a while back. I am using FreeTDS to provide an ODBC driver for a MS-SQL database. When you establish a connection in your application, you reference the tag in the configuration file that is stored in /etc/odbc.ini. In the odbc.ini you make reference to the SQL host and the database of interest. We have multiple database servers that are supposed to mirror each other, more or less, with names that end in 01 and 02 and if you don't point to the right one then as the saying goes "garbage in garbage out".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What are the key stroke combinations for foreign language accents in Office? Flackbait Linux - Newbie 2 04-13-2010 12:55 PM
sql foreign key constraint fails kpachopoulos Programming 2 02-17-2009 07:49 PM
Mysql foreign key doesn't allow update mohtasham1983 Programming 3 07-25-2008 11:56 PM
MySQL Primairy Key problem agallant Programming 6 06-28-2004 12:12 AM
Mysql Foreign Key munna_502 Linux - Software 0 06-12-2004 05:31 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration