Hi I have 2 Tables:

CREATE TABLE IF NOT EXISTS `questions` (
  `question_id` int(11) NOT NULL AUTO_INCREMENT,
  `createddate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updateddate` timestamp NULL DEFAULT NULL,
  `active_flag` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`question_id`),
  UNIQUE KEY `id_UNIQUE` (`question_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE `alarts` (
  `alart_id` BIGINT(20) unsigned NOT NULL AUTO_INCREMENT,
  `alart_name` varchar(45) NOT NULL,
  `interval` int(10) unsigned NOT NULL,
  `contact_id` int(10) unsigned NOT NULL,
  `negative_click_counter` int(10) unsigned NOT NULL,
  `last_time_clicked` TIMESTAMP NOT NULL,
  `alart_sent_counter` int(10) unsigned NOT NULL,
  `alart_types_id` BIGINT(20) unsigned NOT NULL,
  `contact_group_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`alart_id`),
  FOREIGN KEY (`alart_types_id`) REFERENCES alart_types(`alart_types_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;

I want to create new table with two FOREIGN KEY like this:
CREATE TABLE `alart_question_mapping` (
    `alart_question_mapping_id` BIGINT(20) unsigned NOT NULL AUTO_INCREMENT,  
    `question_id` int(11) NOT NULL,
    `alart_id` BIGINT(20) unsigned NOT NULL,
  PRIMARY KEY (`alart_question_mapping_id`),
  FOREIGN KEY (`question_id`) REFERENCES questions(`question_id`),
  FOREIGN KEY (`alart_id`) REFERENCES alart_types(`alart_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;

but I am getting error:
Error Code: 1005. Can't create table 'feedbox_dump_new.alart_question_mapping' (errno: 150)

How can I create this table ?

Thank's.

error 150 reports itself as "Foreign key constraint is incorrectly formed". On first glance the only issue I see is that there is no 'alart_types' table listed (doesn't mean you don't have one but it is referenced by the second foreign key constraint in the table definition). You can try removing the foreign key constraints from the table definition then creating the table and adding the constraints in afterward with an ALTER TABLE statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.