dbTalk Databases Forums  

Foreign Key Constant Problem

comp.databases.mysql comp.databases.mysql


Discuss Foreign Key Constant Problem in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bruce
 
Posts: n/a

Default Foreign Key Constant Problem - 12-19-2010 , 11:29 AM






In my main table I have:
CREATE TABLE maintable {
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
.....
linkid INT UNSIGNED,
....
....
lastfield VARCHAR(10),
PRIMARY KEY(id),
INDEX (linkid ),
FOREIGN KEY (linkid ) REFERENCES subtable(linkid )
) ENGINE=INNODB;

CREATE TABLE subtable (
linkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
linkvalue VARCHAR(20),
PRIMARY KEY (linkid)
) ENGINE=INNODB;

I keep getting an error:
"Foreign key constraint is incorrectly formed"

Appreciate any help on what I'm doing wrong..

Thanks...

Bruce

Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Foreign Key Constant Problem - 12-19-2010 , 02:01 PM






On 12/19/2010 12:29 PM, bruce wrote:
Quote:
In my main table I have:
CREATE TABLE maintable {
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
....
linkid INT UNSIGNED,
...
...
lastfield VARCHAR(10),
PRIMARY KEY(id),
INDEX (linkid ),
FOREIGN KEY (linkid ) REFERENCES subtable(linkid )
) ENGINE=INNODB;

CREATE TABLE subtable (
linkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
linkvalue VARCHAR(20),
PRIMARY KEY (linkid)
) ENGINE=INNODB;

I keep getting an error:
"Foreign key constraint is incorrectly formed"

Appreciate any help on what I'm doing wrong..

Thanks...

Bruce


Does subtable actually exist when you create maintable?

I'm assuming this isn't the actual SQL you're using. Try posting the
exact statements (i.e. cut/paste) you're using.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #3  
Old   
bruce
 
Posts: n/a

Default Re: Foreign Key Constant Problem - 12-19-2010 , 05:45 PM



On Dec 19, 3:01*pm, Jerry Stuckle <jstuck... (AT) attglobal (DOT) net> wrote:
Quote:
On 12/19/2010 12:29 PM, bruce wrote:



In my main table I have:
CREATE TABLE maintable {
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
....
linkid INT UNSIGNED,
...
...
lastfield VARCHAR(10),
PRIMARY KEY(id),
INDEX (linkid ),
FOREIGN KEY (linkid ) REFERENCES subtable(linkid )
) ENGINE=INNODB;

CREATE TABLE subtable (
linkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
linkvalue VARCHAR(20),
PRIMARY KEY (linkid)
) ENGINE=INNODB;

I keep getting an error:
"Foreign key constraint is incorrectly formed"

Appreciate any help on what I'm doing wrong..

Thanks...

Bruce

Does subtable actually exist when you create maintable?

I'm assuming this isn't the actual SQL you're using. *Try posting the
exact statements (i.e. cut/paste) you're using.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck... (AT) attglobal (DOT) net
==================
I discovered my problems when I was preparing to copy/paste the actual
sql. It was a "typo", namely my subtable is named "states" but I
forgot the "s" and used "state".

Thanks...

Bruce

Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.