Académique Documents
Professionnel Documents
Culture Documents
About
Privacy Policy
Products
Archived Projects
Flex FlipCard
HungryFEED
Log File Suite
Phreeze
Support
Contact
RSS
22 Oct
If you get this error while trying to create a foreign key, it can be pretty frustrating. The error about not
being able to create a .frm file seems like it would be some kind of OS file permission error or something
but this is not the case. This error has been reported as a bug on the MySQL developer list for ages, but it
is actually just a misleading error message.
In every case this is due to something about the relationship that MySQL doesn’t like. Unfortunately it
doesn’t specify what the exact issue is. Here is a running list of causes that people have reported for the
dreaded errno 150. I’ve tried to put them in order based on the frequency that I hear about a particular
cause.
You may want to start by running the MySQL command “SHOW INNODB STATUS” immediately after
receiving the error. This command displays log info and error details. (Thanks Jonathan for the tip)
Note: If your script runs fine on one server, but gives an error when you try to run it on a different
server, then there is a good chance that #6 is the problem. Different versions of MySQL have different
default charset setting.
Known Causes:
1. The two key fields type and/or size doesn’t match exactly. For example, if one is INT(10) the key
field needs to be INT(10) as well and not INT(11) or TINYINT. You may want to confirm the field
size using SHOW CREATE TABLE because Query Browser will sometimes visually show just
INTEGER for both INT(10) and INT(11). You should also check that one is not SIGNED and the
other is UNSIGNED. They both need to be exactly the same. (More about signed vs unsigned here).
2. One of the key field that you are trying to reference does not have an index and/or is not a primary
key. If one of the fields in the relationship is not a primary key, you must create an index for that
1 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
field. (thanks to Venkatesh and Erichero and Terminally Incoherent for this tip)
3. The foreign key name is a duplicate of an already existing key. Check that the name of your foreign
key is unique within your database. Just add a few random characters to the end of your key name
to test for this. (Thanks to Niels for this tip)
4. One or both of your tables is a MyISAM table. In order to use foreign keys, the tables must both be
InnoDB. (Actually, if both tables are MyISAM then you won’t get an error message – it just won’t
create the key.) In Query Browser, you can specify the table type.
5. You have specified a cascade ON DELETE SET NULL, but the relevant key field is set to NOT
NULL. You can fix this by either changing your cascade or setting the field to allow NULL values.
(Thanks to Sammy and J Jammin)
6. Make sure that the Charset and Collate options are the same both at the table level as well as
individual field level for the key columns. (Thanks to FRR for this tip)
7. You have a default value (ie default=0) on your foreign key column (Thanks to Omar for the tip)
8. One of the fields in the relationship is part of a combination (composite) key and does not have it’s
own individual index. Even though the field has an index as part of the composite key, you must
create a separate index for only that key field in order to use it in a constraint. (Thanks to Alex for
this tip)
9. You have a syntax error in your ALTER statement or you have mistyped one of the field names in
the relationship (Thanks to Christian & Mateo for the tip)
10. The name of your foreign key exceeds the max length of 64 chars. (Thanks to Nyleta for the tip)
The MySQL documentation includes a page explaining requirements for foreign keys. Though they don’t
specifically indicate it, these are all potential causes of errno 150. If you still haven’t solved your problem
you may want to check there for deeper technical explainations.If you run into this error and find that it’s
caused by something else, please leave a comment and I’ll add it to the list.
138 Comments
Leave a Reply
Name (required)
Website
Comment
Submit Comment
2 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
1.
Stephane
No no no no no and No!!! I’ve been looking closer and closer and closer again. I have 2 tables, the
first one with 2 fields and the second one with only one. The PK I’m trying to build is for 2 Unsigned
INT(10) fields. It just doesn’t work. I’m fed up of this MySQL-Administrator.
Reply
2.
Jason
Hey Stephane, I know this error sucks. MySQL doesn’t tell you what the problem is. But, something
about the fields are not matching or else there may be a conflicting key or something. I don’t know
I’ve never tried a table with only 1 column before – maybe MySQL doesn’t like that? If you find the
answer, post here and maybe it will help someone at some point.
Reply
3.
Niels
Hi, I had this error also. My problem was that I was trying to create a foreign key with a name,
which I had already given another foreign key.
Reply
4.
3 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Jason
Thanks Niels – I updated the post to include that info as well. Hopefully will prevent one of us from
pulling his/her hair out one day!
Reply
5.
Stephane
Reply
6.
Jason
Hey Stephane, it sounds to me like you may be trying to create foreign keys on a “MyISAM” table?
If you need to use foreign keys, you have to use “InnoDB” tables. You can change the table type
with the MySQL Query Browser utility.
Reply
7.
Stephane
Jason,
I am using InnoDB as well. I solved my problem: I returned to the command line on the FreeBSD
6.1 box. I don’t know what’s going on since I installed FreeBSD 6.1 but MySql-Administrator goes
nuts. And just to be sure it wasn’t something weird with my setup, I set up another FreBSD 6.1 box
with the same stuff and still, no luck, same problems. The reason why I’m sure there’s a problem
with this mix (FreeBSD 6.1, mysql-server 5.1.6_2 and mysql-administrator 1.1.6) is because
4 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
everything works fine with mysql-administrator from a remote machine. I’ve been successfully
doing my foreign keys remotely from a Win32 box as well as from a Fedora box.
I’ll dig that out eventually. Thanks to all for your input.
Reply
8.
Stephane
Guys, I’d like to insert some revealing snapshots here. I’ll setup a blog and provide you with a link
for it. MySql-Administrator 1.1.6 and FreeBSD 6.1 do not cooperate well.
Reply
9.
Paul
Reply
10.
Srinath
Very useful tip.. Was a bit frustrated and got help from this article!!
Reply
11.
FRR
5 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Hi, I had the same problem but in my case the cause of the problem was that the “Colum
Charset†and “Colum Collate†was different between the key fields. It’s interesting
although the both tables have already configured the same “Charset†and “Collate†, the
fields could have different values in these parameters.
Reply
12.
Jason
Thanks FRR – I’ll add that to the list as well. That one would definitely be difficult to troubleshoot
Reply
13.
Venkatesh Naicker
Index missing on the column that is being tried to have foreign key. Creating index on that column
fixed it.
Reply
14.
andy
Hi folks,
I’ve just discover another interesting case. You can get also errno: 150 when you try to do the
following: create table A, create table B with the relation many to 1 (respectively) and then create
table C which is in relation one to many with table B and it is also in relation one to many with table
A. I though this relations should work fine but I figure out if I take one of them I can create all the
tables A, B and C if you know what I mean
Reply
6 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
15.
Erichero
You might want to mention for newbies like me, that your foreign key must point to a primary key. I
assumed that you could just point to anything.
Reply
16.
Jason
Thanks everyone for posting your causes – I’ll continue to update the article with your ideas.
Reply
17.
Christian
Jesus, this is really a crap error message. It’s also thrown if you have the wrong syntax:
ALTER TABLE ADD CONSTRAINT fk_foo FOREIGN KEY (foo_id) references foo
throws this error. It should of course throw a syntax exception… This works:
ALTER TABLE ADD CONSTRAINT fk_foo FOREIGN KEY (foo_id) references foo (foo_id)
Reply
18.
sime
Bravo! In my case, problem was about MyISAM and INNODB table types.
Reply
7 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
19.
Justin
Thanks for this post. Was beating my head against the wall on this one until I found this.
In my case, it turned out to be a problem with the jack ass trying to create the table. I was a little
overzealous in my copy/pasting writing the SQL to create the tables and forgot to change the name
of one of the columns. When I tried to create another table later with a foreign key that referenced
the correct name, it failed. Took me a little while to realize that the problem wasn’t with the table
that was erroring out, but with the one I was referencing.
Thanks again.
Reply
20.
Ezequiel from Buenos Aires
My problem is that you have to create an INDEX on the table where you have the referencing
column. Example:
)
ENGINE= INNODB;
8 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
ENGINE= INNODB;
Made me lost like 3 hours to work it out. It’s strange that nobody else said this… we’re migrating
from MSSQL Server 2000 to MySQL 4.0.20 (pretty old stuff, I still have to figure out what to do
with triggers!)
Good Luck!
Reply
21.
Omar
Thanks for the tricks, but after hours of testing and re testing we found another issue : There should
be no ‘defaut 0′ close on the foreign key column in the child table.
Greetings,
Reply
22.
Sammy
Make sure when use of ON DELETE SET NULL with a foreign key, it is not setted to NOT NULL
Reply
[...] is not the case – it is just a silly, misleading message. I started googling for it and found some
good tips on how to avoid this error at VerySimple Dev Blog. I spent over two hours testing all
possible solutions listed in that post. [...]
Reply
24.
Richard Kennard
9 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
THANK YOU! As many others have commented above, this blog entry saved me a great deal of
time and hair pulling.
Reply
25.
Vamsikrishna Nadella
This Article helped me a lot. I was really frustrated with the error and the InnoDB/MyISAM
combination was killing me. One of the tables was MyISAM. Thanks you very much for putting up
this article. It saved me a lot of time.
– Vamsi
Reply
26.
Correa Rodrigo
I can’t alter tables, drop key, nothig. I can’t do nothing with my database. And always show this
message:
#1005 – Can’t create table ‘#sql-a2f_2e680′ (errno: 13)
Reply
27.
ILVC
Thank you for your blog! My problem was not on the list but at least this article gave me light to
hunt what was happening. In my case the problem was simply that I had TWO primary keys in the
referenced table by accident! I simply dropped the other primary key and presto.
Reply
28.
10 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Jonathan Kohler
Sometimes when you get this error you can get more information by checking the InnoDB log with
‘SHOW INNODB STATUS;’ It helped me pinpoint the problem.
Reply
29.
freak
In my case datatypes of both tables were not same, one was int with unsigned and other was just int.
I put the unsigned in the other one and it worked fine. Both tables should be innoDB
Reply
30.
Mateo
If you think you’ve tried it all, check that you are trying to reference an EXISTING field. So,
perhaps you have “id_table” instead of “idtable”. The “_” can be a baddie sometimes
Reply
31.
Sergio
This post really helped me. My problem was that the referenced table was MyISAM. I changed to
InnoDB and everything works nice now. Thank you Jason.
Reply
32.
Edd
11 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
My problem of migratina an MS Access db to MySQL was solved by rewriting the ALTER TABLE
table1 ADD FOREIGN KEY… statement. There was a syntax error, I guess, from the fact that the
two FK were a composite PK in table1. Excellent blog, btw.
Reply
33.
J Jammin
I had this problem, but it was the famous user error. I defined the foreign key column as ‘NOT
NULL’ and then specified that on delete set NULL. Makes perfect sense that MYSQL refused to
create the table.
Reply
34.
John
Reply
35.
crisu
Reply
36.
crisu
12 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
37.
B
THANK YOU SO MUCH! This has been driving me crazy for the last couple days and I finally got it
working. I didn’t know every foreign key has to have a unique name withing the database. What a
pain in the ass!
Reply
38.
Simon
Reply
39.
Gustavo
Thanks, you saved me a lot of time and headache. Mine was #1.
Reply
40.
George Calm
Thank you, Jason. I was struggling with this error for hours now. Excellent posting!
Reply
13 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
41.
Alex Grim
Great post. I happened across this while researching this error. One thing that you mentioned what
that “one or the other must be indexed”.
But i wish to add that if one or the other (PK or FK) is part of a combined primary key/index, you
will STILL get this error, you MUST create a separate index for the field you wish to reference with
your FK.
Thanx
Reply
42.
Jason
Thanks Alex. I didn’t know that was the case but I don’t use combo keys too often. I can see that
one stumping somebody so I added your tip to the article.
Reply
43.
Victoria
Ty #3 !!
Reply
44.
Mat
Also, UNSIGNED and ZEROFILL properties for the foreign key columns must match.
14 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
45.
Jim
Reply
46.
Dougie
I placed the primary key field when using the foreign and that work, just as Christian did further
above.
Jim try this code:
CREATE TABLE PCP
(
PCPID MEDIUMINT NOT NULL,
PCPName VARCHAR(75),
PCPMD MEDIUMINT NOT NULL,
PRIMARY KEY (PCPID),
FOREIGN KEY (PCPMD) REFERENCES PCP (PCPMD)
);
BTW i noticed in you code your pulling data using the (foreign key) from itself as the primary key is
in the same table, have you tried pulling data from a primary key of another table.
Example
FOREIGN KEY (PCPMD) REFERENCES PCP2 (PCPMD)
Reply
15 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
47.
shob
Thanks a lot.. i was going nuts on this bizzare err.. this aricle saved a lot … mine was INNODB ==
MYISAM … [:)]
Reply
48.
Dave Miller
Reply
49.
Arturo
I had a problem where the primary key of the referenced table was not the first column on the table
and I couldn’t use it as a foreign key. Droping the table and having the primary key as the first
column fixed the issue. Both tables were Innodb
Cheers,
Arturo
Reply
50.
Ivan
Thanks!
Number 3 worked for me. Actually it is very obvious that foreign key name must be unique
Ivan
16 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
51.
varma
i nead to know very soon.. is there any possible to use char 0r varchar to set auto_incriment
Reply
52.
Jason
varma – i don’t think it is possible to use varchar as auto-increment. i’m not sure the reason to do
that unless it is to support some legacy schema?
Reply
53.
Matt and Cody
Thank you so much. This helped us find the solution to our problem. You are the best
Reply
54.
Mamta
Dear Jason,
Thanks a lot.. your blog helped me to solve my problem. thanks again.
Reply
17 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
55.
Andreas
Thank you verry much! Just didn’t know there has to be uniq foreign key names.
Reply
56.
Pete
Thank you for this article. Just printed it out. It just saved the remaining hair I am left with!
Reply
57.
Vinod Pillai
1) First of all make sure both parent and child table should be InnoDB.
Now when you create the foreign key in child table it creates the key_Name by default now you
have to change that key_Name.
2) Now make sure that Foreign Column name should exactly match with the field name of the
parent table.
Reply
58.
Dele Agagu
18 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Whao!! couldnt help but post.i tried all sorts but nothing worked until i search for the error and
whola!! your blog blew my mind!! thanks for this
Reply
59.
Dele Agagu
Make sure that if your referenced table has the primary key column as UNSIGNED, then the
referencing table needs to have the referencing column as UNSIGNED too.
Reply
60. Shift Instinct » Blog Archive » MySQL Error Number 1005 Can’t create table ‘.mydb#sql-
328_45.frm’ (errno: 150)
Reply
61.
Tor Andre
I was using ActiveRecord/NHibernate to keep my db up to date. Since this was before release 1.0 I
had ActiveRecord to automatically update my database (using ‘hibernate.hbm2ddl.auto’). This
results in dropping every table and generate them again every time I rebuild my project.
I got stuck with this error, and there was one table I was unable to create. I tried everything,
manually without foreign keys as well.
What solved it was to create the table WITH a foreign key but not naming it. Once doing that, I
edited the table in Query Browser and found two (2) foreign keys with same reference. It seemed as
the table was dropped as it should be, but the previous foreign key was stuck somewhere (couldn’t
find it in the system tables either).
I dropped both the foreign keys and the table, then clean build the project (resulting in drop and
create statements for all tables), and it WORKED!
Happy debugging!
Reply
19 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
62.
Rahul Master
Reply
63.
Aswin Anand
If the table for which the foreign key has to be applied contains data, this could happen. I took a
backup of the existing data, truncated the table, ran the alter table query again. This time it went on
smoothly.
Reply
64.
Find an Appraiser
I checked everything in this list and still got the error. Then I just dropped and recreated the
database, ran new create script with only difference being my new table having PK varchar(255)
instead of int(3), and it all worked fine. Strange, but there you have it.
Reply
65.
Amin Abbasopour
You’re great!
Reply
20 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
66.
Spenner
I had quite a few problems creating FK’s and found out that it’s good practice to use different FK
names for each table.
Apparently MySQL does not like multiple instances of the same FK name in the same DB for
different tables which I also think is quite logical.
Thanks to everyone else on this post for all the info provided as well
Reply
67.
pavan
thanks a lot
Reply
68.
Marco Agurto
I don’t write in english very well so a try to do my best work. I try to fix my alter with the nine steps
but I cant fix my problem So I could fix my problem using the alter in the same order. In table one
DE_PROC, CO_PROC in the table two CO_PROC, DE_PROC change the order of table two, I am
happy again lucky for everybody
Reply
69.
jegreat
21 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
make sure that the foreign key u r trying to add is already present in the reference table!! if this
value is not a primary key in the reference table; then u wil get this error
Reply
70.
Nyleta
After a lot of swearing and reading through your suggestions I tried something from left field and
shortened the name of my foreign key, and bingo! So if you are still adding to your list up the top,
can I suggest shortening of the foreign key name.
Reply
71.
werutzb
Hi!
Thanks,
Werutz
Reply
72.
Jason
Thanks Nyleta, I found the max length is 64 chars, so I’ll add this to the list
Reply
22 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
74.
anonymous
It the definition of the local columns that is different to the ForeignKey-Column (such like
“UNSIGNED”, (), etc.)
Reply
75.
Paresh
Thanks for the information. I had the problem of one is SIGNED and the other is UNSIGNED.
Thanks again
Reply
76.
Nayyereh
Hi,
Thank you Niels, I had this problem and with your suggestion solved.
Reply
77.
Deepak
23 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
The solution that worked for me (having ensured all the above were verified was the length of the
name of FK. I gave it a shorter name and it worked.
Reply
78.
Brian
“You should also check that one is not SIGNED and the other is UNSIGNED.” Ahh..HAH!
-Brian
Reply
79.
Ignace
Some good advice: make sure all your tables are dropped in your database before running your sql
installation script! I personally use:
before i place my table definition, however when i ran the script when their were already tables in
the db i got the #1005 error, when i used the same script on an empty db it worked just fine.
Reply
80.
the.janitor
Reply
24 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
81.
Shan
This was incredibly helpful. I usually avoid these kind of sites, but this helped what was proving to
be an extremely frustrating issue. Brilliant.
Reply
82. MySQL Error Number 1005 Can’t create table ‘.mydb#sql-328_45.frm’ (errno: 150) « Fabio
Cepeda
Reply
83.
chicco
It’s a dirty way to solve it but if you enclose the alter table statement between
SET FOREIGN_KEY_CHECKS=0;
and
SET FOREIGN_KEY_CHECKS=1;
it works
Reply
84.
HKASLCA
Thanks.
I’ve solved the problem.
Reply
25 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
85.
Lainey
Can I say I love you? I have spent hours trying to figure out this issue and it turned out that both
tables were MyISAM tables! Gotta love the internet and people like you who post solutions to
problems!
Reply
86.
CJ
ONE MORE:
Make sure your tables are written in the definition file BEFORE you try and make a foreign key on
that table.
Reply
87.
kirov
yeah, one more time THANK YOU, I was ready unninstal MySQL because of that, and the problem
was stupid index on column. Why they couldn’t do a error message about this, I don’t understand.
Reply
88. MySQL Error Number 1005 Can’t create table ‘.mydb#sql-328_45.frm’ (errno: 150)
[...] from here directly. Bookmark it! These icons link to social bookmarking sites where readers can
share and [...]
Reply
26 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
89.
ynabid
when I change my tables engine to innoDB and I want to create a foreign key for a attribut that has
data type=varchar, that not work but when I set flag to binary it work.
Reply
90.
Plat
Thanks for the troubleshootin’ list. This saved me an incredible amount of time. I caught an
UNSIGNED/SIGNED mismatch prior to this page, but didn’t think to check InnoDB vs MyISAM.
My new editor must be defaulting to InnoDB for some reason.
Reply
91.
Gerhard Kratz
Gerhard Kratz :
I got rid of this problem, when I added the name of the primary key of the table to be
referenced to the foreign key constraint. Example:
NOT: FOREIGN KEY ( articleFK ) REFERENCES Article ON DELETE …
BUT: FOREIGN KEY ( articleFK ) REFERENCES Article ( articleID ) ON DELETE
…
Reply
92.
Gerhard Kratz
If one wants to
- CREATE TABLE A with FOREIGN KEY ( ab ) REFERENCES B
27 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
93.
Lauro Valente
Reply
Jason
that’s a good point Lauro. You can actually have data in the tables, but you have to make sure
that every row works with the new key. a lot of times when you try to add a key you’ll have
to clean up the data first.
Reply
94.
Heti
thaaaaanks a ton … got the prblem fixed in lesser time than expected. ))))) i am so happppyyyy
Reply
95.
Radek
28 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
96.
Dave
Thanks heaps!!!!!!!!!!!!!!!
Reply
97.
thao
thankyou!
Can i translate this Posts to vietnamese and post it in our public site?
Reply
Jason
hi thao, that would be ok – it would be appreciated if you link back to my site as well.
Reply
98.
zachariah
29 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
99.
che
Reply
100.
Sax
Reply
101.
Rohit
Reply
102.
alk
anonymous :
It the definition of the local columns that is different to the ForeignKey-Column (such
like “UNSIGNED”, (), etc.)
30 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
103.
ann_an
Reply
104. What I like! » Blog Archive » Error #1005 – Can’t create table… en MySQL al intentar crear una
relacion 1-M
Reply
105.
Xavier Montero
I’ve been messing with the same problem. The DATA TYPE was identical. In both cases a
VARCHAR(36) which I use to store as primary keys standard UUID values as “string”.
Nevertheless, being them text, they have a “charset”, and one table was “UTF” and the other
“LATIN”.
Changing the charset to be coherent (both to utf8 or both to latin) I was able to create the FOREIGN
KEY without the error of “can’t create table…”
Reply
106.
Chris
31 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Also:
If the primary key you want to connect to your foreign key is UNSIGNED make it G** D*** SURE
that your foreign key is also UNSIGNED.
Reply
107.
wirawit
Reply
108.
Firas Abd Alrahman
but the foreign key field does Have “Not null ” flag
Just removed the check by mysql GUI administrator and Everything was just fine
Reply
109.
Amal Kaluarachchi
I had the same problem and spent many hours on troubleshooting. This article helped me to figure it
out the issue. It was I have set the ondelete to set null where the table field is set not null.
Thanks
Reply
32 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
110.
Brian Weiss
My issue came up because I was trying to import/build a new table that had foreign keys in tables
that didn’t exist. The export from the old MYSQL server exported the tables in alpha numeric order,
but on the new server, my CONSTRAINT statement was referencing foreign keys in tables that
didn’t yet exist as they were further down in the file. So I just cut and pasted the Create table
statements into a new order, where all the ones that needed foreign keys were built after the tables
they referenced. And it worked! Hope this helps others…
Reply
111.
AJ
Reply
112.
Erika
Thanks, It solved my problem. One table had UNSIGNED checked and the other not. Pretty simple
but very hard to find.
Reply
113.
Daniel Cairol
33 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Reply
114.
Kai-Jin
Reply
115.
Amit Singh
Reply
116.
Kulish kushwah
The error may occur, if both the fields having different storage engine.
Reply
117.
sim4000
Many thanks.
I remove “NOT NULL” from the FK column and it works!
Reply
34 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
118.
_Jon
Reply
119.
VISHNU
Reply
120.
pkak
Reply
121.
csen
35 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
Good!As I have try the first one ,my problem was solved!
haha,thanks a lot!
Reply
122.
Lloyd
You’re a saviour! My error was number 5, I had FK set to “on delete set null” which was
referencing a column that was “not null” in hind sight my mistake was so blindingly obvious but at
the time I just couldn’t see the wood for the trees.
Cheers
Reply
Nikki
The thing that I noticed is the Character set of both the columns should be same….for e.g. A
table has primary key named ID,Now the table which want to use this key as foreign key ,the
column to which it is relating to be the foreign key should have same character set as that of
the A table as well as the size should also be same.
Reply
123.
N3r1
36 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
`hotel`.`reservation`(`res_num`),
Reply
124.
Joe Devon
I had a really weird one I just fixed… Nothing on this list made a difference…but I noticed that a
second column (NOT USED AT ALL IN ANY WAY BY THE FK) in the original table had a
unique index…so on a whim, I deleted it…was able to add a foreign key, then reinstate the unique
index…
No idea why that should matter…but if none of the above helps you, try it…
Reply
125.
Rolf
If MySQL is acting like the usual piece of crap that it is, you might want to do this:
SET FOREIGN_KEY_CHECKS = 0;
To disable checks. It worked for me so far, as I couldn’t find the problem, despite your wonderfully
compiled list, and don’t intend so spend the rest of my day on this.
Once done, there is still the option to re-enable the sadistic masochistic checks:
SET FOREIGN_KEY_CHECKS = 1;
Hope this info will be added to your post
Reply
126.
Kumar Pushkar
Reply
37 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
127.
vamsi
Reply
128.
Astghik
Reply
129.
Gopal
Hi,
Reply
130.
Sofus
38 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
had a primary key namet agnetID (should have been agentID), tried to refference that by calling the
name that it should have had, but haddn’t
I know that it is a stuppid fault, but a plausible one none the less.
Thanks for your website!
Reply
131.
Kay
Ouch. I just had 2 hours of frustration with this stupid error message. And going though the list
suggestions above, number 6 finally did it. The field’s character set was UTF8 the referenced table,
but the database default character set is LATIN1 and the new table I created didn’t have character
set specified for that field. So it was created as LATIN1…
Boy this sucks! Now I have to search through my database definitions and find out what other tables
may give me a headache in the future.
Thanks for this page. It should really be on MySQL’s web site. Why are the devs so ignorant to the
general user public and through non-descript error messages on the screen like this? If the innodb
engine knows what the problem is (which I checked with the show innodb status), then the error
MySQL throws should be able to be more acurate than it is right now. (my two cents)
Reply
132.
Mike
Thank you so much, issie 5 was my problem, I was trying to “ON DELETE SET NULL” for a NOT
NULL column, doh!
Reply
133.
Fletcher
Reply
39 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
134.
andre
Segui todos os passos e obtive sucesso vlw, o que mais pegou: criar indice com os campos
relacionados nas duas tabelas, mesma tipagem de campos ate com o mesmo tamanho,Thanks!
(Automatic Portuguese to English translation: I followed all the steps and got success VLW, which
took over: create index with the related fields in both tables, the same type of the fields even with
the same size, Thanks!)
Reply
135.
Dennis Herdman
THANK YOU!
Reply
October 2006
Mon Tue Wed Thu Fri Sat Sun
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
« Sep Nov »
40 of 41 1/28/2011 7:07 PM
MySQL Error Number 1005 Can't create table '.mydb#sql-328_45.frm' (... http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-creat...
loading
41 of 41 1/28/2011 7:07 PM