Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    4

    Unanswered: 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;

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the FK and PK have to match exactly

    you have one of them as UNSIGNED and the other one not
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2009
    Posts
    4
    Thanks Dude

    you safe my life

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •