MySQL 1005 Error : SQLSTATE: HY000 (ER_CANT_CREATE_TABLE) Message: Can't create table '%s' (errno: 150)


Error No : 1005
Error Type : Server Error
Error Code : 1005 SQLSTATE: HY000 (ER_CANT_CREATE_TABLE)
Error Message : Can't create table '%s' (errno: %d)
This error may occur when you are trying to create a table and it fails. 
There are many reasons that may cause this issue. 
One of the reason is related to Foreign Key constraint that is not formed correctly (Error code 150).
MySQL QueryLanguage: SQL
CREATE TABLE `prog_lang` (
`lang_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`lang_name` VARCHAR(100) NOT NULL,
    `lang_desc` VARCHAR(255) NOT NULL,
    `active_stat` CHAR(1)
);
CREATE TABLE `topic` (
    `topic_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `topic_desc` TEXT NOT NULL,
    `lang_id` INT NOT NULL,
    CONSTRAINT `fk_prog_lang` FOREIGN KEY(`lang_id`) REFERENCES `prog_lang`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Make sure that Engine and CHARSET of the tables match: ENGINE=InnoDB DEFAULT CHARSET=utf8.

Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency