database - Why am I getting "error code 1005 can t create c errno 150 mysql "? -


Edit # 2: - After the reply of Spencer 75 93, that is, The table was successfully created and the foreign key was added successfully

but without adding the foreign key , and then adding them using the alter table statement

Now I wonder why? When we create tables and then add foreign key constraints using the alter table statement, why does this work, and when we make it the table statement?


I am creating the following tables in my database, the first two were successfully created but the third is giving this error.

I checked my database for those points in which I could understand. Please tell me why I got this error.

  create table (AIID INT (255) tap AUTONCrment, name VARCHAR (5000), code VARCHAR (5000), primary key (A_ID)); Make Table B (BIIDIT (255) tap AUTANCCimment, B_NAN VARCHAR (5000), Primary Key (B_ID)); CREATE TABLE C (- Error code 1005 TC errno can create 150 mysql a_id INT (255), - FK b_id INT (255), - FK primary key (a_id, b_id), foreign key (a_id) reference one (a_id) , Foreign Key (BIID) Reference B (BIID));   

Edit: -

I performed these three statements separately (all INT types to 11 - Thank you for commenting on Michael Berkowski), and my surprise is that he created the tables, but it was logged (if I am using the correct word):

 Create a table (a_id INT (11) No NULL AUTO_INCREMENT, name VARCHAR (5000), code VARCHAR (5000), primary key (a_id)) 0 row (s) affected in 0.156 seconds 3 5 0 1: 03: 54 CREATE TABLE B (b_id INT (11) No NULL AUTO_INCREMENT, b_name VARCHAR (5000), Primary key (b_id) 0 row (s) 0.234 affected seconds 3 to 6 01:03:58 CREATE TABLE C ( - Error code 1005 TC errno can create 150 mysql a_id INT (11), - FK b_id INT (11), - FK primary key (a_id, b_id), foreign key (a_id) one (a_id) reference, foreign key ( BIID) Reference B (BIID) 0 Rows Affected 0.203 sec   

All three tables have been created, but the error has been returned to the third table. Create table `A`> (` a_id` integer (11) to prepare table, No NULL AUTO_INCREMENT, `name` varchar (5000) default zero,` code` varchar (5000) default zero, primary key (`a_id`)) engine = InnoDB default charset = UTF8 table` b` (`b_id` integer (11 ) No NULL AUTO_INCREMENT, `b_name` varchar (5000) default zero, primary key (` b_id`)) engine = InnoDB default charset = UTF8

But there is no problem in OP Create Table statement; They work as the default storage engine with both MyMessage and InDebbi. (Not sure about any other storage engine, we do not see a storage engine specified, and I guess the default is either InnoDB or MyISAM.)

  show Variables like 'default_storage_engine'   

To debug it, try running Table C without the foreign key constraint definitions and verify that the table was successfully created (255 long modifiers value us as weird Do not make it the default by 11?)

  create table C (AIID int comment 'FK referee A.A.ID', BIID int comment 'FK referee BB_ID', Primary key (A_ID, B_ID));   

Then try adding foreign key constraints:

  Alternate table C ADD CONFRIEND FK_c_a Foreign key (AID) reference (a_id);   

Make sure that the column is in a_id a , and the definition matching (whether it is possible that the column < code> id (instead of a_id ) table a ?) < / html>

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -