Home > Uncategorized > Can’t create table (errno: 150)

Can’t create table (errno: 150)


Mysql

Hi there,

This is not the first or the second time that I spend time digging this fucking error whie creating a foreign key in Mysql.

This error code is telling you that your constraint is failing, possible due to some issues:

  • table referenced doest not exist/not created yet
  • column type from REFERENCES is different then the on you are using
  • foreign key name is duplicated
      This is common when we are copy and pasting some other sql from other tables, check this one!

Double check these issues and you can solve your problem.

orr……..

If you to be more hard-core

Set Mysql to ignore the constrain checks by doing:

SET foreign_key_checks = 0;
--> YOUR_SQL
SET foreign_key_checks = 1;

Remembering that this option is not the best one, because you are ignoring checks, be aware of that.


  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: