If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Relationship Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-12-09, 01:22
junaidali junaidali is offline
Registered User
 
Join Date: Feb 2009
Posts: 4
Relationship Problem

Hi All,

i have two tables and structur of them is as follows.. but when i try to create relationship it gives me following error.

Executed Statement : "alter table `dbblueice_textile`.`products` add constraint `FK_products` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`supplier_id`)"

Error: Can't create table '.\dbblueice_textile\#sql-d0_42.frm' (errno: 150)

Tables:
Products :
`product_id` int(10) unsigned NOT NULL auto_increment,
`bar_code` varchar(13) ,
`product_name` varchar(45)
`trade_price` decimal(10,2) default '0.00',
`unit_price` decimal(10,2) NOT NULL,
`unit` varchar(10) NOT NULL,
`min_qty` int(10) unsigned NOT NULL,
`max_qty` int(10) unsigned NOT NULL,
`category_id` int(10) unsigned NOT NULL,
`supplier_id` int(11) default '0',
`created_by` int(10) unsigned NOT NULL,
`date_created` datetime NOT NULL,
`modified_by` int(10) unsigned NOT NULL,
`date_modified` datetime NOT NULL,
`is_active` enum('Y','N') NOT NULL default 'Y',
`is_deleted` enum('Y','N') NOT NULL default 'N',
PRIMARY KEY (`product_id`),
KEY `FK_products_1` (`category_id`),
CONSTRAINT `FK_products_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

Suppliers : DROP TABLE IF EXISTS `dbblueice_textile`.`suppliers`;
CREATE TABLE `dbblueice_textile`.`suppliers` (
`supplier_id` int(10) unsigned NOT NULL auto_increment,
`supplier_name` varchar(45) NOT NULL,
`phone` varchar(20) NOT NULL,
`mobile` varchar(20) NOT NULL,
`email` varchar(45) NOT NULL,
`address` varchar(75) NOT NULL,
`city_id` int(10) unsigned NOT NULL,
`created_by` int(10) unsigned NOT NULL,
`date_created` datetime NOT NULL,
`modified_by` int(10) unsigned NOT NULL,
`date_modified` datetime NOT NULL,
PRIMARY KEY (`supplier_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
Reply With Quote
  #2 (permalink)  
Old 02-12-09, 04:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
the FK and PK have to match exactly

you have one of them as UNSIGNED and the other one not
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-13-09, 01:42
junaidali junaidali is offline
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks Dude

you safe my life
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On