"Jesse" <[EMAIL PROTECTED]> wrote on 12/22/2005 02:51:21 PM:

> I am trying to add referential integrity to my database.  I'm trying to 
add 
> a foreign key reference to one of my tables, but I'm getting an error 
when I 
> try to do so.  Here's what I'm executing:
> 
> ALTER TABLE Campers ADD CONSTRAINT FK_Activities FOREIGN KEY 
FK_Activities 
> (ID)
> REFERENCES ActivitySelections (PersonID)
> ON DELETE CASCADE
> ON UPDATE CASCADE;
> 
> When I execute this in the command line utility, I get the error, "Can't 

> create table '.\fccamp\#sql-33c_30.frm' (errno: 150)"
> 
> Does anyone know what this means, and how I can fix it?  I'm using MySQL 

> 5.?? on a Windows XP Pro (development machine).
> 
> Thanks,
> Jesse 
> 

the "Simplified Rules" for creating foreign keys:

a) both tables must be InnoDB
b) all columns involved (in both parent and child tables) must be the 
leftmost portion of at least one index. It's preferable if the parent 
column(s) is/are part of a PK or UNIQUE index.
c) there can be no data already in the child table that would otherwise 
violate the key you are trying to create.

To see more details about this error (or any other problem going on in 
InnoDB), run the command SHOW InnoDb STATUS. There will be about 40 or 50 
lines of output so if it scrolls off of the screen and your screen buffer 
isn't big enough, you will not be able to see the details of the error 
because what you want to look at is near the top of the report. Resize 
your buffer and try again.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine


Reply via email to