Mysql ERROR 1005: Can’t create Table (errno: 150) when creating a reference constraint in mysql results in an ERROR message that cannot create a reference constraint.
A rough picture of what went wrong
1, foreign key reference type is different, such as the primary key is int foreign key is char
2. The column referenced in the main table could not be found
3, the primary key and foreign key character encoding is not consistent, may also be different storage engineThe problem I ran into was that none of the above was true, but it did succeed after removing a foreign key constraint. One thing is for sure, this error was caused by a foreign key constraint.
A rough picture of what went wrong
1, foreign key reference type is different, such as the primary key is int foreign key is char
2. The column referenced in the main table could not be found
3, the primary key and foreign key character encoding is not consistent, may also be different storage engineThe problem I ran into was that none of the above was true, but it did succeed after removing a foreign key constraint. One thing is for sure, this error was caused by a foreign key constraint.
To summarize the experience:
In fact, in a MySQL database, if there are more than one database, it is better to write SQL with the name of the database, such as:
CREATE TABLE `testdb`.`user_visitor_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT 'id',
`user_ip` varchar(15) COLLATE utf8_bin DEFAULT NULL COMMENT 'ip',
`refer_url` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT 'source',
`visit_time` timestamp NULL DEFAULT NULL COMMENT 'time',
`leave_time` timestamp NULL DEFAULT NULL COMMENT 'leave time',
`module_name` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT 'moudle name',
`news_id` int(11) DEFAULT NULL COMMENT 'Access to information on the information page id',
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
KEY `seoID_idx` (`seo_id`),
CONSTRAINT `seo_msg_id` FOREIGN KEY (`seo_id`) REFERENCES `college_seo_msg` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='User access log';
Read More:
- How to Fix MySQL ERROR 1130 (HY000): Host ‘XXXX’ is not allowed to connect to this MySQL server
- How to Solve MYSQL ERROR: relation “table_name” does not exist
- MySQL Build table error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL ser
- [Solved] MySQL5.6.44 [Err] 1067 – Invalid default value for create_date settlement programme
- How to Solve can‘t connect to local mysql server through socket ‘/var/lib/mysql/mysql.sock‘
- MySQL 8.0 error 1114 (HY000): the table’sbtest1’is full (Fixed)
- How to Solve MYSQL Error: Failed to start MySQL 8.0 database server
- How to release Oracle PLSQL data lock table
- [Solved] flicksql cdc mysql to kafka Connect Error: org.apache.flink.table.api.ValidationException…
- MySQL Error: [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file
- [Solved] com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
- SQL Server Deletes a table foreign key constraint Error [Solved]
- MySQL | ERROR : Every derived table must have its own alias [Solved]
- Error creating foreign key in MySQL: 1215 cannot add the foreign key constraint
- Error 1406 (22001) in MySQL: data too long for column (Fixed)
- How to Solve mysql [Err] 1067-Invalid default value for
- IDEA maven Config MYSQL Connection Error: Could not create connection to database server.
- Solve MySQL table can not query, modify, delete and other operations and appear stuck
- [Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)
- Remote connection to MySQL database error: is not allowed to connect to this MYSQL server solution