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 3393324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:02:14+00:00 2026-05-18T04:02:14+00:00

i know im doing something stupid here but its been a few years since

  • 0

i know im doing something stupid here but its been a few years since i worked with foreign keys, projects i was always on we did it with code not the db. here are my tables:

delimiter $$

CREATE TABLE `show_survey_name` (
  `idSHOW_survey_name` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL COMMENT 'the name of the survey',
  `start_date` date default NULL COMMENT 'the start date for the survey',
  `end_date` date default NULL COMMENT 'end date for the survey',
  `deleted` tinyint(1) NOT NULL default '0' COMMENT 'has the survey been deleted',
  `survey_launch_location` varchar(255) default NULL COMMENT 'where in showpro does this survey pop up.',
  `optional` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`idSHOW_survey_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

delimiter $$

CREATE TABLE `show_store_location` (
  `store_id` int(11) NOT NULL auto_increment,
  `clientID` int(11) default '0',
  `store_code` varchar(4) default NULL,
  `store_name` varchar(255) default NULL,
  `store_link` varchar(255) default NULL,
  `store_email` varchar(255) default NULL,
  `store_phone` varchar(50) default NULL,
  `store_fax` varchar(50) NOT NULL default '',
  `store_contact` varchar(255) default NULL,
  `region_code` varchar(5) default NULL,
  `store_update_code` varchar(50) default NULL,
  `Deleted` int(11) NOT NULL default '0',
  `unbock_term_id` varchar(45) default NULL,
  `north_dealerid` varchar(45) default NULL,
  `north_clientid` varchar(45) default NULL,
  `tide_dealerid` varchar(45) default NULL,
  `tide_msgtype` varchar(45) default NULL,
  `tide_dlrname` varchar(45) default NULL,
  `smart_dlrname` varchar(45) default NULL,
  PRIMARY KEY  (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

delimiter $$

CREATE TABLE `show_survey_name_store` (
  `idSHOW_survey_name_store` int(11) NOT NULL,
  `SHOW_survey_name_idSHOW_survey_name` int(11) NOT NULL,
  `SHOW_store_location_store_id` int(11) NOT NULL,
  PRIMARY KEY  (`idSHOW_survey_name_store`),
  KEY `fk_SHOW_survey_name_store_SHOW_survey_name1` (`SHOW_survey_name_idSHOW_survey_name`),
  KEY `fk_SHOW_survey_name_store_SHOW_store_location1` (`SHOW_store_location_store_id`),
  CONSTRAINT `fk_SHOW_survey_name_store_SHOW_store_location1` FOREIGN KEY (`SHOW_store_location_store_id`) REFERENCES `show_store_location` (`store_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_SHOW_survey_name_store_SHOW_survey_name1` FOREIGN KEY (`SHOW_survey_name_idSHOW_survey_name`) REFERENCES `show_survey_name` (`idSHOW_survey_name`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

when i try to do a simple insert into the linking table that links stores to surveys,

insert into SHOW_survey_name_store (SHOW_store_location_store_id, idSHOW_survey_name_store) values (3, 3)

i get

java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint fails (`showroom/show_survey_name_store`, CONSTRAINT `fk_SHOW_survey_name_store_SHOW_store_location1` FOREIGN KEY (`SHOW_store_location_store_id`) REFERENCES `show_store_location` (`store_id`) ON DEL)

i know im probably doing something simple wrong, and yes, record 3 exists in the store and the survey table. it should insert, i don’t see why its not.

thanks guys

  • 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-05-18T04:02:15+00:00Added an answer on May 18, 2026 at 4:02 am

    Ok, first of all, I don’t know how you managed to create these tables because you have show_store_location set as MyISAM which doesn’t work with foreign keys. MySQL didn’t let me create it until I changed that to InnoDB. I also had to change the creation order of the tables. (I have edited your question to address both of these issues)

    Secondly, your actual problem is not with your foreign key, it’s with your horrible, horrible naming convention. I had to look at this for five minutes and sort through all the various verbal combinations of “show”, “store” and “id” to realize that you are just plain using the wrong column name in the insert (2nd one)

    insert into show_survey_name_store (SHOW_store_location_store_id, SHOW_survey_name_idSHOW_survey_name) values (3, 3);
    

    So, please, clean up your column and table names. Not only for yourself, but for the poor souls who have to look at this after you’ve moved on.

    And lastly, I had to modify show_survey_name_store like so before the insert even worked

    ALTER TABLE `show_survey_name_store` MODIFY COLUMN `idSHOW_survey_name_store` INTEGER NOT NULL AUTO_INCREMENT;
    

    You may not want it to be auto-increment, and that’s fine, but then you’ll have to define a default value or remove the NOT NULL.

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

Sidebar

Related Questions

I know this sounded stupid. But I gotta be doing something wrong here. Say,
I have some really weird crash here, ive got it before, but i thought
I have a table that looks something like this. <table> <thead> <tr> <th>Foo</th> <th>Bar</th>
I've been drooling over Django all day while coding up an internal website in
All, I am very new to stored procedures in general but I am struggling
I have a couple of checkboxes on my form, and I don't want to
I am trying to query the windows desktop search API using SQL. I have
I'm mostly a spoiled Windows + Visual Studio (or Borland C++ or whatever, in
Suppose I have a number of related classes that all have a method like
I'm trying to make a jQuery plugin that executes a method on a timer.

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.