MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 25th, 2004, 08:10 AM
kostasat kostasat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 kostasat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy errno:150

Hi, i have a problem with creating a foreign key in table departments.
here's how i created the tables:

create table customer(
custid int not null auto_increment primary key,
--------more fields------
salesman varchar(30)
) type=innodb;

create table departments(
departid int not null auto_increment,
cust_id int not null,
-----fields---------
department varchar(30),
primary key (departid),
foreign key (cust_id) references customer(custid) on delete restrict
) type=innodb;

relation between 2 tables is 1 to many (and not many to many).

And I don't know if table departments needs 2 primary keys(departid and cust_id)

the error i get is "ERROR 1005: Can't create table '.\crm\departments.frm' (errno: 150)".

can someone help me with this problem?
to your help is greatly appreciated. thanks.

Reply With Quote
  #2  
Old December 10th, 2004, 06:02 AM
Angela Angela is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Netherlands
Posts: 11 Angela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool

Ok, the 2nd table needs to have an index on the referencing column as well.This can be part of the primary key, or a seperate one.See example:

CREATE TABLE parent(id INT NOT NULL,
PRIMARY KEY (id)
) TYPE=INNODB;
CREATE TABLE child(id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) TYPE=INNODB;

So, add the INDEX customer_id(cust_id) before your FOREIGN KEY and it should work.
Mind you: I didn't test this.

Hope this helps,
Angela

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > errno:150


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway