Can anyone tell me what i'm doing wrong here?I'm trying to set up a one-to-one relationship between two tables, but it just doesn't work.These are my tables: -
CREATE TABLE prices
-
(
-
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY ,
-
price FLOAT NOT NULL
-
-
) ENGINE=INNODB ;
-
CREATE TABLE films
-
(
-
film_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY ,
-
name VARCHAR(30) NOT NULL,
-
FOREIGN KEY (film_id) REFERENCES prices (id)
-
-
-
) ENGINE=INNODB ;
-
And this is the insert statement i'm using to populate them(I'm getting the following error:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`video_library`.`films`, CONSTRAINT `films_ibfk_5` FOREIGN KEY (`film_id`) RE
FERENCES `prices` (`id`))) -
INSERT INTO prices (price)
-
VALUES (1.99),
-
(2.99),
-
(3.99),
-
(4.99),
-
(5.99),
-
(6.99),
-
(7.99),
-
(8.99),
-
(9.99),
-
(10.99),
-
(11.99),
-
(12.99),
-
(13.99);
-
-
INSERT INTO films (name)
-
VALUES ('The Godfather'),
-
('The Godfather II'),
-
('The Shawshank redemption'),
-
('Pulp fiction'),
-
('12 Angry men'),
-
('Schindler\'s List'),
-
('Fight club'),
-
('Inception'),
-
('The green mile'),
-
('Dog Day Afternoon'),
-
('The Dark Knight'),
-
('Saving Private Ryan'),
-
('Se7en');
-
Thanks in advance
2 4095
Really? Godfather is cheaper than Godfatehr II?
you need to rethink the price ;)
anyway:
pointer number one this is not a very smart way to design your database. do two things
1. Remove Auto Increment constraints from the second database.
2 and insert all the the data in table two with proper id taken from table on1
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ralph Smith |
last post by:
I'm having trouble copying a database to another machine. Here are the two
table's in ths database and the sql commands:
DROP TABLE IF EXISTS `clients`;
CREATE TABLE `clients` (
`client_id`...
|
by: jijo kuruvila |
last post by:
actually my code looks like this
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.Columns.Visible=true;...
|
by: Frank |
last post by:
Hello,
I have a dataset with 2 tables and a relation (parent - child). I linked
that ds to a datagrid. Shows everything fine (very little coding for such
functionality!).
But.. in the child row I...
|
by: fuimens |
last post by:
Hi,
With mysql-4.0.20, I have a problem inserting data with foreign key
references, MySQL saying ERROR 1216: Cannot add or update a child row:
a foreign key constraint fails
The message is...
|
by: Zorglub |
last post by:
Hi,
I have a windos form with two datagrids Master and Detail, I use a dataset
with two datatable and a relation between Table1 and Table2. I set the
datagrid like :
DataViewManager dsView =...
|
by: Ivan |
last post by:
Thanks to answer topic previous!!!!
I use this script to update one table
MERGE INTO EIS.CLI_HISTORY TXN
USING EIS.CLI_MAPING CLI
ON TXN.CLIENTID = CLI.CLIENTID
WHEN MATCHED AND...
|
by: Harshpandya |
last post by:
Hi I am new at ASP and MYSQL.
I am Using Navicat to access MYSQL database.
My Problem is when i create the foreign key in "Navicat" -it gives me this error.
1452-cannot add or update child...
|
by: nitinkhare1 |
last post by:
Please help,I'm very frustated.
when I ADD
the data in kn_history_question table of htbase_tst database....it giving the error "Cannot add or update a child row:a foreign key constraint...
|
by: muaddubby |
last post by:
Hi
I've got a situation with a dataset that contains two tables with a many-to-one relationship, and am trying to extract the data in xml format. When I execute the GetXml() method, and exception...
|
by: semanticnotion |
last post by:
Hi sir i want to transform the data of one table into another through foreign key but the following error come to my browser
Here is my code and data base structure.
CREATE TABLE IF NOT...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |