mysql - Error Code: 1005. Can't create table '...' (errno: 150) -



mysql - Error Code: 1005. Can't create table '...' (errno: 150) -

i searched solution problem on net , checked questions no solution worked case.

i want create foreign key table sira_no metal_kod.

alter table sira_no add together constraint metal_kodu foreign key(metal_kodu) references metal_kod(metal_kodu) on delete set null on update set null ;

this script returns:

error code: 1005. can't create table 'ebs.#sql-f48_1a3' (errno: 150)

i tried adding index referenced table:

create index metal_kodu_index on metal_kod (metal_kodu);

i checked metal_kodu on both tables (charset , collation). couldn't find solution problem. have idea? in advance.

edit: here metal_kod table:

metal_kodu varchar(4) no pri durum bit(1) no metal_ismi varchar(30) no ayar_yogunluk smallint(6) yes 100

error code: 1005 -- there wrong primary key reference in code

usually it's due reference fk field not exist. might have typo mistake,or check case should same, or there's field-type mismatch. fk-linked fields must match definitions exactly.

some known causes may :

the 2 key fields type and/or size doesn’t match exactly. example, if 1 int(10) key field needs int(10) , not int(11) or tinyint. may want confirm field size using show create table because query browser visually show integer both int(10) , int(11). should check 1 not signed , other unsigned. both need same. one of key field trying reference not have index and/or not primary key. if 1 of fields in relationship not primary key, must create index field. the foreign key name duplicate of existing key. check name of foreign key unique within database. add together few random characters end of key name test this. one or both of tables myisam table. in order utilize foreign keys, tables must both innodb. (actually, if both tables myisam won’t error message - won’t create key.) in query browser, can specify table type. you have specified cascade on delete set null, relevant key field set not null. can prepare either changing cascade or setting field allow null values. make sure charset , collate options same both @ table level individual field level key columns. you have default value (ie default=0) on foreign key column one of fields in relationship part of combination (composite) key , not have it’s own individual index. though field has index part of composite key, must create separate index key field in order utilize in constraint. you have syntax error in alter statement or have mistyped 1 of field names in relationship the name of foreign key exceeds max length of 64 chars.

for more details refer : mysql error number 1005 can’t create table

mysql mysql-error-1005

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -