|
|
|
|
|
|
| Author |
Message |
Chris White *nix forums beginner
Joined: 21 Apr 2006
Posts: 43
|
Posted: Wed Jul 19, 2006 8:38 pm Post subject:
Re: Error when creating Foreign Key
|
|
|
On Wednesday 19 July 2006 01:07 pm, Jesse wrote:
| Quote: | `ID` int(10) unsigned NOT NULL auto_increment,
`CTID` int(11) NOT NULL,
|
the storage types aren't the same. change CTID to INT(10) UNSIGNED NOT NULL
and it should work.
--
Chris White
PHP Programmer/DBank
Interfuel
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Jesse *nix forums addict
Joined: 14 Dec 2005
Posts: 56
|
Posted: Wed Jul 19, 2006 8:07 pm Post subject:
Re: Error when creating Foreign Key
|
|
|
Sure. Here is the information on both tables:
DROP TABLE IF EXISTS `karate`.`custtournaments`;
CREATE TABLE `karate`.`custtournaments` (
`ID` int(10) unsigned NOT NULL auto_increment,
`CustID` int(10) unsigned NOT NULL default '0',
`TournamentName` varchar(45) NOT NULL default '',
`TournamentDate` datetime NOT NULL default '0000-00-00 00:00:00',
`Style` varchar(20) default NULL,
`BegLevel` varchar(20) NOT NULL default '',
`EndLevel` varchar(20) NOT NULL default '',
`Match` varchar(20) NOT NULL default '',
`SubDiv` varchar(60) NOT NULL default '',
`BegWt` int(10) unsigned NOT NULL default '0',
`EndWt` int(10) unsigned NOT NULL default '0',
`BegAge` int(10) unsigned NOT NULL default '0',
`EndAge` int(10) unsigned NOT NULL default '0',
`BegHtFt` int(10) unsigned NOT NULL default '0',
`BegHtIn` int(10) unsigned NOT NULL default '0',
`EndHtFt` int(10) unsigned NOT NULL default '0',
`EndHtIn` int(10) unsigned NOT NULL default '0',
`Gender` varchar(1) NOT NULL default '',
`Ring` varchar(2) default NULL,
`Order` int(10) unsigned NOT NULL default '0',
`DivNum` varchar(7) NOT NULL default '',
`Time` varchar( default NULL,
`Status` varchar(3) NOT NULL default '',
`Judge1` varchar(30) default NULL,
`Judge1Score` double(5,1) default '0.0',
`Judge2` varchar(30) default NULL,
`Judge2Score` double(5,1) default '0.0',
`Judge3` varchar(30) default NULL,
`Judge3Score` double(5,1) default '0.0',
`Judge4` varchar(30) default NULL,
`Judge4Score` double(5,1) default '0.0',
`Judge5` varchar(30) default NULL,
`Judge5Score` double(5,1) default '0.0',
`ScoreKeep` varchar(30) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `karate`.`custpoints`;
CREATE TABLE `karate`.`custpoints` (
`ID` int(11) NOT NULL auto_increment,
`Status` varchar(3) default NULL,
`Association` varchar(15) default NULL,
`Points` tinyint(3) default NULL,
`CTID` int(11) NOT NULL,
PRIMARY KEY (`ID`),
KEY `CTID` (`CTID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Thanks,
Jesse
----- Original Message -----
From: "Chris White" <chriswhite@interfuel.com>
To: <mysql@lists.mysql.com>
Sent: Wednesday, July 19, 2006 2:33 PM
Subject: Re: Error when creating Foreign Key
| Quote: | On Wednesday 19 July 2006 10:25 am, Jesse wrote:
MySQL Error Number 1005
Can't create table '.\karate\#sql-304_9.frm' (errno: 150)
KEY `FK_custpoints_1` (`CTID`)
REFERENCES `custtournaments` (`ID`)
can you show us the column declarations for these two?
Any idea why this is happening, and how to fix it?
Thanks,
Jesse
--
Chris White
PHP Programmer/DBlankSlate
Interfuel
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=jlc@msdlg.com
|
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Chris White *nix forums beginner
Joined: 21 Apr 2006
Posts: 43
|
Posted: Wed Jul 19, 2006 6:33 pm Post subject:
Re: Error when creating Foreign Key
|
|
|
On Wednesday 19 July 2006 10:25 am, Jesse wrote:
| Quote: | MySQL Error Number 1005
Can't create table '.\karate\#sql-304_9.frm' (errno: 150)
|
KEY `FK_custpoints_1` (`CTID`)
REFERENCES `custtournaments` (`ID`)
can you show us the column declarations for these two?
| Quote: | Any idea why this is happening, and how to fix it?
Thanks,
Jesse
|
--
Chris White
PHP Programmer/DBlankSlate
Interfuel
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Jesse *nix forums addict
Joined: 14 Dec 2005
Posts: 56
|
Posted: Wed Jul 19, 2006 6:22 pm Post subject:
Re: Error when creating Foreign Key
|
|
|
| Quote: | Is it possible you're in the wrong database (different from
'custtournaments') when you issue this command?
|
No. I've tried in SQL Browser, EMS SQL Manager, and MySQL Command line,
making sure in each case that I have the karate database selected. I have
also re-typed it in MySQL Command line, eliminating the reference to the
karate database, and got the same error.
I tried the SHOW INNODBSTATUS. I did find something in there that may hint
at the problem:
060719 14:07:40 Error in foreign key constraint of table karate/#sql-304_12:
FOREIGN KEY FK_custpoints_1 (CTID)
REFERENCES custtournaments (ID)
ON DELETE CASCADE
ON UPDATE RESTRICT:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html
for correct foreign key definition.
I checked through the page listed above, and my syntax appears to be
correct. It appears to be saying that there is no index present for the ID
field in the custtournaments table. But, I've double-checked, and there IS
an index there.
Foreign keys are a little "foreign" to me at the moment. I understand what
they are, and what they do, however, which file to put this on always causes
me a little problems. Here's the current relationship as I can explain it:
Parent: CustTournaments
Children: CustPoints.
In other words, for 1 CustTournaments record, there could be multiple
CustPoints records. Now, my understanding is that the ForeignKey refers to
a "parent record" in for a Child Database. So, for my purposes, Im saying
that if they delete the CustTournaments record, I want it to delete all of
the CustPoints record. So, I add a foreign key to the CustPoints table
pointing towards it's parent record. I've stored the Parent Key value in
the field CTID in the Child table (custpoints), which points to the ID field
in the parent record (custtournaments).
Is my understanding flawed?
Any more light you can shed on this is appreciated.
Thanks,
Jesse
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Dan Buettner *nix forums Guru Wannabe
Joined: 13 Oct 2005
Posts: 119
|
Posted: Wed Jul 19, 2006 5:37 pm Post subject:
Re: Error when creating Foreign Key
|
|
|
Jesse, a stab in the dark here, with some info from the manual.
A foreign key constraint is in My Code erroneously coded,
If MySQL gives the error number 1005 from a CREATE TABLE
statement, and the error message string refers to errno 150, then
the table creation failed because a foreign key constraint was not
correctly formed. Similarly, if an ALTER TABLE fails and it refers
to errno 150, that means a foreign key definition would be incorrectly
formed for the altered table. Starting from version 4.0.13, you can
use SHOW INNODB STATUS to look at a detailed explanation of the
latest InnoDB foreign key error in the server.
You explicitly specify the database of one table with
ALTER TABLE `karate`.`custpoints`
but later you don't explicitly specify the database of the other with:
REFERENCES `custtournaments` (`ID`)
Is it possible you're in the wrong database (different from
'custtournaments') when you issue this command?
Also check out SHOW INNODB STATUS for more info on what might be going on.
HTH,
Dan
On 7/19/06, Jesse <jlc@msdlg.com> wrote:
| Quote: | I'm using MySQL 5 with InnoDB tables. I'm trying to create a foreign key,
but when I try, it's giving me an error. I've tried this with the
MySQLQuery Browser, and EMS SQL Manager 2005. I get the following error in
the Query Browser:
Error while executing query.
ALTER TABLE `karate`.`custpoints` ADD CONSTRAINT `FK_custpoints_1` FOREIGN
KEY `FK_custpoints_1` (`CTID`)
REFERENCES `custtournaments` (`ID`)
ON DELETE CASCADE
ON UPDATE RESTRICT;
MySQL Error Number 1005
Can't create table '.\karate\#sql-304_9.frm' (errno: 150)
Any idea why this is happening, and how to fix it?
Thanks,
Jesse
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=drbuettner@gmail.com
|
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Jesse *nix forums addict
Joined: 14 Dec 2005
Posts: 56
|
Posted: Wed Jul 19, 2006 5:25 pm Post subject:
Error when creating Foreign Key
|
|
|
I'm using MySQL 5 with InnoDB tables. I'm trying to create a foreign key,
but when I try, it's giving me an error. I've tried this with the
MySQLQuery Browser, and EMS SQL Manager 2005. I get the following error in
the Query Browser:
Error while executing query.
ALTER TABLE `karate`.`custpoints` ADD CONSTRAINT `FK_custpoints_1` FOREIGN
KEY `FK_custpoints_1` (`CTID`)
REFERENCES `custtournaments` (`ID`)
ON DELETE CASCADE
ON UPDATE RESTRICT;
MySQL Error Number 1005
Can't create table '.\karate\#sql-304_9.frm' (errno: 150)
Any idea why this is happening, and how to fix it?
Thanks,
Jesse
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Dec 04, 2008 2:25 am | All times are GMT
|
|
Debt Help | Hypotonic Cerebral Palsy | MPAA | Credit Counseling | Car Loans
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|