I'm trying to add a foreign key to a table and I get the following error:
ERROR 1005 (HY000): Can't create table 'tablename.#sql-5cf_179' (errno: 150)
I use this query:
alter table table_1 add foreign key (col_1) references table_2 (col_2);
Both columns have the same datatype (varchar(50)), same collation, they're not null and I changed the default value to something different from null too.
I checked SHOW ENGINE INNODB STATUS and got this:
Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint. Note that the internal storage type of ENUM and SET changed in tables created with
= InnoDB-4.1.12, and such columns in old tables cannot be referenced by such columns in new tables. See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html for correct foreign key definition.
I have no idea what do to next...
EDIT more info added:
|snmptt_nodes | CREATE TABLE `snmptt_nodes` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`ip` varchar(50) NOT NULL DEFAULT 'no_ip_found',
`last_response` datetime NOT NULL,
`state` varchar(50) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1
| snmptt | CREATE TABLE `snmptt` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`eventname` varchar(4000) DEFAULT NULL,
`eventid` varchar(4000) DEFAULT NULL,
`trapoid` varchar(4000) DEFAULT NULL,
`enterprise` varchar(4000) DEFAULT NULL,
`community` varchar(4000) DEFAULT NULL,
`hostname` varchar(4000) DEFAULT NULL,
`agentip` varchar(50) NOT NULL DEFAULT 'no_ip_found',
`category` varchar(4000) DEFAULT NULL,
`severity` varchar(4000) DEFAULT NULL,
`uptime` varchar(4000) DEFAULT NULL,
`traptime` varchar(4000) DEFAULT NULL,
`formatline` varchar(4000) DEFAULT NULL,
`timestamp` datetime DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=206352 DEFAULT CHARSET=latin1 |
| snmptt_listpolls | CREATE TABLE `snmptt_listpolls` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(50) NOT NULL DEFAULT 'no_ip_found',
`polling_time` int(10) NOT NULL,
`communitydata` varchar(100) NOT NULL,
`snmp_oid` varchar(250) DEFAULT NULL,
`lastcheck` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=latin1 |