mysql won't allow foreign key
===

Many people had this problem already, but there was no fitting solution in other posts.

I have two tables, one named "sales", the other named "host_flags". I would like to have a foreign key for host_flags.sales_id to sales.id, but mysql won't let me! I have primary indexes defined in each table, so I wonder why...

The host_flags table already has a foreign key on the column host_id, but even when I tried and created the foreign key for the sales id first, it wouldn't let me.

The tables look like:

    CREATE TABLE `sales` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `email` varchar(255) DEFAULT NULL,
      `password` varchar(255) DEFAULT NULL,
      `creation` datetime DEFAULT NULL,
      `lastupdate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

    CREATE TABLE `host_flags` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `host_id` int(11) DEFAULT NULL,
      `sales_id` int(11) DEFAULT NULL,
      `creation` datetime DEFAULT NULL,
      `lastupdate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`),
      KEY `host_id6` (`host_id`),
      CONSTRAINT `host_id6` FOREIGN KEY (`host_id`) REFERENCES `hosts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I get this error message:

    MySQL said: Can't create table 'primarydata.#sql-191_1' (errno: 150)


Thanks!

Charles