This is another stupid error. It has to do with trying to successfully set foreign keys in MySQL.
ERROR 1005: Can’t create table (errno: 150)
Great, that’s fantastic. Here’s an example of where this error will occur.
CREATE TABLE main(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
);
CREATE TABLE other(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
main_id INT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(main_id) REFERENCES main(id)
);
So I’m trying to make the table “other” reference the table “main” through the foreign key “main_id” and, if you try it, it’ll throw an Error 150.
Want the solution?
The foreign key “main_id” has to have the exact same type as the primary key that it references. In the example, “main_id” in the table “other” has the type INT NOT NULL while “id” in the table “main” has the type “INT UNSIGNED NOT NULL” and also AUTO_INCREMENT, but that isn’t something we have to worry about. To make things incredibly clear, here’s the working example.
CREATE TABLE main(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
);
CREATE TABLE other(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
main_id INT UNSIGNED NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(main_id) REFERENCES main(id)
);
To solve ‘MySQL ERROR 1005: Can’t create table (errno: 150)‘ you likely just have to ensure that your foreign key has the exact same type as the primary key. Hope it helps.
The database engine is not innodb
This might be another answer, though I haven’t tested it. If so, you can make sure your tables are INNODB by specifying in the CREATE TABLE statement:
ENGINE=InnoDB;
Or you can alter existing tables with this:
ALTER TABLE my_table ENGINE = InnoDB;
Here is an extensive list of different reasons that you can get errno: 150, along with other MySQL foreign key errors:
http://eliacom.com/wpErrNo150.php
Awesome, thanks :)
worked
Thanks very much!!! It worked fine!!!!
Thank you, worked like a charm!
Thanks! Awesome. =D
Espero esto le sirva a alguien, investigando sobre este error se produce por dibersas causas las principales que no cohinciden la llave primaria con la foranea, es decir tienen tipos diferentes, es decir int varchar etc, o tienen atributos diferentes como por ejemplo el unsigned o binary etc, si es el caso anterior se soluciona poniendo tanto llave primaria como foranea del mismo tipo las dos y con los mismos atributos, tambien es recomendado que sean de la misma longitud ya que si bien es sierto que la longitud no es tomada encuenta al momento de relacionar puede causar problemas al momento de pasar a la incercion de datos y demas dml.
Otro motivo por el cual ocurre este error es por que esta repetido el nombre de campo
es decir puede que en la bd ya haya un campo con el nombre id por lo que la solucion seria simplemente cambiar el nombre a id1 por ejemplo.
otro motivo por el cual ocurre este error es el tipo demotor usado en las tablas es decir puede ser que una sea innodb y la otra myisam la solucion es que las dos deben ser del mismo tipo de motor.
Por ultimo el motivo puede ser tambien el constrainter puede que este configurado como on delete set null y el campo noadmite valores nulos es decir es not null
Como ya lo habia dicho espero le sirva a alguien esta info y si es asi pueden pegar el comentario en algun otro foro para ayudar a mas gente, saludos
Thanks for writing such a good post to motivate the world to do some better things. Everyone have a cheap and but comfort zone where they feel relaxed. But there are rare people in the world accept the challenges and give something different what people looking for. I am sure people will enjoy your tips.
Pingback: Google
Pingback: URL
Pingback: Google
Pingback: Google
Pingback: Google
Pingback: Google
Pingback: tottally free dating sites
Pingback: Google
Pingback: Top 7 Error 1005 Hy000 Can T Create Table The 27 Latest Answer
Pingback: Mysql Errno 150? Top 7 Best Answers - Budget-template.com
Pingback: Mysql Error 1005? Top 7 Best Answers - Budget-template.com
Pingback: online pharmacies
Pingback: madridbet
Pingback: madridbet
Pingback: meritking
Pingback: sex
Pingback: fuvk google
Pingback: fuck google
Pingback: madridbet
Pingback: Ошибка ссылку foreign key невозможно добавить 1005
Pingback: Error 1005 mysql
Pingback: Error code 1005 sql
Pingback: madridbet
Pingback: meritking giriş
Pingback: Error code 150 in mysql
Pingback: Sql create table error 150
Pingback: Sql general error 1005
Pingback: Sql error 1005 foreign key constraint
Pingback: Ошибка 1005 mysql — Решение и исправление самых разных ошибок
Pingback: Ошибка ссылку foreign key невозможно добавить 1005 — Большая энциклопедия ошибок и их решений
Pingback: child porn
Pingback: child porn
Pingback: grandpashabet
Pingback: grandpashabet
Pingback: child porn
Pingback: cratosroyalbet
Pingback: child porn
Pingback: child porn
Pingback: child porn
Pingback: child porn
The way you put together the information on your posts is commendable. I would highly recommend this site. You might also want to check my page Webemail24 for some noteworthy inputs about Blogging.
Your posts in this blog really shine! Glad to gain some new insights, which I happen to also cover on my page. Feel free to visit my webpage Seoranko about Cosplay and any tip from you will be much apreciated.
Pingback: spinco
Hey, if you are looking for more resources, check out my website Article Sphere as I cover topics about Blogging. By the way, you have impressive design and layout, plus interesting content, you deserve a high five!
You’ve done an impressive work on your website in covering the topic. I am working on content about Thai-Massage and thought you might like to check out YH6 and let me what you think.
Pingback: child porn
Your writing style is cool and I have learned several just right stuff here. I can see how much effort you’ve poured in to come up with such informative posts. If you need more input about Airport Transfer, feel free to check out my website at 46N
Pingback: child porn
Pingback: Buy followers instagram
Pingback: web sitesi kurma
Pingback: cristiano ronaldo skills
Pingback: child porn