I have following 2 tables in my database:
CREATE TABLE `address` (
`id` bigint(20) NOT NULL auto_increment,
`entity_creation_timestamp` datetime default NULL,
`entity_version` bigint(20) default NULL,
`city` varchar(255) default NULL,
`country` varchar(255) NOT NULL,
`county` varchar(255) default NULL,
`label` varchar(255) default NULL,
`line1` varchar(255) default NULL,
`line2` varchar(255) default NULL,
`line3` varchar(255) default NULL,
`state` varchar(255) NOT NULL,
`zip` varchar(255) NOT NULL,
`zip_extension` varchar(255) default NULL,
`party_id` bigint(20) default NULL,
`list_index` int(11) default NULL,
`last_updated_timestamp` datetime default NULL,
PRIMARY KEY (`id`),
KEY `fk_party_postaladdress_id` (`party_id`),
CONSTRAINT `fk_party_postaladdress_id` FOREIGN KEY (`party_id`) REFERENCES `sims_party` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
the other one :
CREATE TABLE `state` (
`state` varchar(255) NOT NULL,
`name` varchar(255) default NULL,
PRIMARY KEY (`state`),
KEY `pk_state` (`state`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
I am trying to apply a foreign key constraint on 'state' column in 'address' table to 'name' column in the 'state' table..
the command i am using for the same is :
ALTER TABLE address
ADD CONSTRAINT FK_address_state FOREIGN KEY (state)
REFERENCES state(state) ON DELETE RESTRICT ON UPDATE RESTRICT;
But each time I run this command, I get the following error:
ERROR 1005 (HY000): Can't create table 'db.#sql-75c_da' (errno: 150)
Any idea where its going wrong...???