![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Level | Code | Message | |
|
Error | 1005 | Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) | |
#2
| |||
| |||
|
|
Here is the table I am attempting to create. DROP TABLE proc_trans_distinctions IF EXISTS; CREATE TABLE proc_trans_distinctions ( `m_id` int(10) unsigned NOT NULL, `p_id` int(10) unsigned NOT NULL, `mid` varchar(256) NOT NULL DEFAULT '0', `cc_id` int(10) unsigned NOT NULL, distinction_class TINYINT UNSIGNED NOT NULL, PRIMARY KEY (p_id,mid,cc_id) USING BTREE, CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants), CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id), CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; The tables and columns in the references clauses are correct, and the columns in question are primary keys in those tables and have the same type as the columns in the corresponding fields in this table. This produces the following error: ERROR 1005 (HY000): Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) mysql> SHOW ERRORS; +-------+------ +---------------------------------------------------------------------- + | Level | Code | Message | +-------+------ +---------------------------------------------------------------------- + | Error | 1005 | Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) | +-------+------ +---------------------------------------------------------------------- + 1 row in set (0.00 sec) In the online MySQL 5.0 reference manual, I see: 13.2.12.1. InnoDB Error Codes The following is a nonexhaustive list of common InnoDB-specific errors that you may encounter, with information about why each occurs and how to resolve the problem. •1005 (ER_CANT_CREATE_TABLE) Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error –1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table. If I create the table WITHOUT the foreign keys, and then ADD the foreign keys, I get the following result: mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants); Query OK, 0 rows affected (0.07 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id); ERROR 1005 (HY000): Can't create table 'merchants2.#sql-1248_d' (errno: 150) mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id); Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 I really don't understand why two out of the three foreign keys get properly created while the third fails. I do not see any significant differences in the syntax used to create them. can anyone shed light on what is going awry here, and how to fix it? |
#3
| |||
| |||
|
|
El 16/02/2011 18:30, Ted Byers escribi /wrote: Here is the table I am attempting to create. DROP TABLE proc_trans_distinctions IF EXISTS; CREATE TABLE proc_trans_distinctions ( * *`m_id` int(10) unsigned NOT NULL, * *`p_id` int(10) unsigned NOT NULL, * *`mid` varchar(256) NOT NULL DEFAULT '0', * *`cc_id` int(10) unsigned NOT NULL, * *distinction_class TINYINT UNSIGNED NOT NULL, * *PRIMARY KEY (p_id,mid,cc_id) USING BTREE, * *CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants), * *CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id), * *CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; The tables and columns in the references clauses are correct, and the columns in question are primary keys in those tables and have the same type as the columns in the corresponding fields in this table. This produces the following error: ERROR 1005 (HY000): Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) mysql> *SHOW ERRORS; +-------+------ +---------------------------------------------------------------------- + | Level | Code | Message * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * *| +-------+------ +---------------------------------------------------------------------- + | Error | 1005 | Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) | +-------+------ +---------------------------------------------------------------------- + 1 row in set (0.00 sec) In the online MySQL 5.0 reference manual, I see: 13.2.12.1. InnoDB Error Codes The following is a nonexhaustive list of common InnoDB-specific errors that you may encounter, with information about why each occurs and how to resolve the problem. 1005 (ER_CANT_CREATE_TABLE) Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error 1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table. If I create the table WITHOUT the foreign keys, and then ADD the foreign keys, I get the following result: mysql> *ALTER TABLE proc_trans_distinctions * * *-> * *ADD CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants); Query OK, 0 rows affected (0.07 sec) Records: 0 *Duplicates: 0 *Warnings: 0 mysql> *ALTER TABLE proc_trans_distinctions * * *-> * *ADD CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id); ERROR 1005 (HY000): Can't create table 'merchants2.#sql-1248_d' (errno: 150) mysql> *ALTER TABLE proc_trans_distinctions * * *-> * *ADD CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id); Query OK, 0 rows affected (0.04 sec) Records: 0 *Duplicates: 0 *Warnings: 0 I really don't understand why two out of the three foreign keys get properly created while the third fails. *I do not see any significant differences in the syntax used to create them. can anyone shed light on what is going awry here, and how to fix it? Run this as well: * * * * SHOW INNODB STATUS In practice, I've found that many foreign key errors get hidden there. Thanks, That's a great tip - something I'd missed, but while it hi- |
#4
| |||
| |||
|
|
On Feb 16, 1:00 pm, "Álvaro G. Vicario" alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: El 16/02/2011 18:30, Ted Byers escribi /wrote: Here is the table I am attempting to create. DROP TABLE proc_trans_distinctions IF EXISTS; CREATE TABLE proc_trans_distinctions ( `m_id` int(10) unsigned NOT NULL, `p_id` int(10) unsigned NOT NULL, `mid` varchar(256) NOT NULL DEFAULT '0', `cc_id` int(10) unsigned NOT NULL, distinction_class TINYINT UNSIGNED NOT NULL, PRIMARY KEY (p_id,mid,cc_id) USING BTREE, CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants), CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id), CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; The tables and columns in the references clauses are correct, and the columns in question are primary keys in those tables and have the same type as the columns in the corresponding fields in this table. This produces the following error: ERROR 1005 (HY000): Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) mysql> SHOW ERRORS; +-------+------ +---------------------------------------------------------------------- + | Level | Code | Message | +-------+------ +---------------------------------------------------------------------- + | Error | 1005 | Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) | +-------+------ +---------------------------------------------------------------------- + 1 row in set (0.00 sec) In the online MySQL 5.0 reference manual, I see: 13.2.12.1. InnoDB Error Codes The following is a nonexhaustive list of common InnoDB-specific errors that you may encounter, with information about why each occurs and how to resolve the problem. 1005 (ER_CANT_CREATE_TABLE) Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error 1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table. If I create the table WITHOUT the foreign keys, and then ADD the foreign keys, I get the following result: mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants); Query OK, 0 rows affected (0.07 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id); ERROR 1005 (HY000): Can't create table 'merchants2.#sql-1248_d' (errno: 150) mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id); Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 I really don't understand why two out of the three foreign keys get properly created while the third fails. I do not see any significant differences in the syntax used to create them. can anyone shed light on what is going awry here, and how to fix it? Run this as well: SHOW INNODB STATUS In practice, I've found that many foreign key errors get hidden there. Thanks, That's a great tip - something I'd missed, but while it hi- lighted one thing I missed, the error still makes no sense. Here is the definition of the processors table (that the failed foreign key references: CREATE TABLE `processors` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `processor_name` varchar(256) NOT NULL, `tz_processor` varchar(26) NOT NULL DEFAULT 'GMT', `tz_processor_DST` varchar(45) DEFAULT 'UTC', `processor_name2` varchar(45) DEFAULT NULL, `payment_type` varchar(2) NOT NULL DEFAULT 'cc', PRIMARY KEY (`p_id`) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; Thus, I changed the type of p_id in my new table to be int(11) instead of int(10), but still the error remains. From "SHOW INNODB STATUS", the error is: "LATEST FOREIGN KEY ERROR '------------------------ "110216 13:21:27 Error in foreign key constraint of table merchants2/ #sql-1248_d: "FOREIGN KEY (p_id) REFERENCES processors (p_id): "Cannot find an index in the referenced table where the "referenced columns appear as the first columns, or column types "in the table and the referenced table do not match for constraint. "Note that the internal storage type of ENUM and SET changed in "tables created with>= InnoDB-4.1.12, and such columns in old tables "cannot be referenced by such columns in new tables. "See http://dev.mysql.com/doc/refman/5.1/...nstraints.html "for correct foreign key definition." Obviously, the referenced column in the processors table exists, it is the first column, and it is the primary key in that table, and it is now the same tpye even to the size of the integer. |
#5
| |||
| |||
|
|
El 16/02/2011 19:29, Ted Byers escribió/wrote: On Feb 16, 1:00 pm, "Álvaro G. Vicario" alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> *wrote: El 16/02/2011 18:30, Ted Byers escribi /wrote: Here is the table I am attempting to create. DROP TABLE proc_trans_distinctions IF EXISTS; CREATE TABLE proc_trans_distinctions ( * * `m_id` int(10) unsigned NOT NULL, * * `p_id` int(10) unsigned NOT NULL, * * `mid` varchar(256) NOT NULL DEFAULT '0', * * `cc_id` int(10) unsigned NOT NULL, * * distinction_class TINYINT UNSIGNED NOT NULL, * * PRIMARY KEY (p_id,mid,cc_id) USING BTREE, * * CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants), * * CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id), * * CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; The tables and columns in the references clauses are correct, and the columns in question are primary keys in those tables and have the same type as the columns in the corresponding fields in this table. This produces the following error: ERROR 1005 (HY000): Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) mysql> * *SHOW ERRORS; +-------+------ +---------------------------------------------------------------------- + | Level | Code | Message * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *| +-------+------ +---------------------------------------------------------------------- + | Error | 1005 | Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) | +-------+------ +---------------------------------------------------------------------- + 1 row in set (0.00 sec) In the online MySQL 5.0 reference manual, I see: 13.2.12.1. InnoDB Error Codes The following is a nonexhaustive list of common InnoDB-specific errors that you may encounter, with information about why each occurs and how to resolve the problem. 1005 (ER_CANT_CREATE_TABLE) Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error 1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table. If I create the table WITHOUT the foreign keys, and then ADD the foreign keys, I get the following result: mysql> * *ALTER TABLE proc_trans_distinctions * * * -> * * *ADD CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id)REFERENCES merchants (idmerchants); Query OK, 0 rows affected (0.07 sec) Records: 0 *Duplicates: 0 *Warnings: 0 mysql> * *ALTER TABLE proc_trans_distinctions * * * -> * * *ADD CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id)REFERENCES processors (p_id); ERROR 1005 (HY000): Can't create table 'merchants2.#sql-1248_d' (errno: 150) mysql> * *ALTER TABLE proc_trans_distinctions * * * -> * * *ADD CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id); Query OK, 0 rows affected (0.04 sec) Records: 0 *Duplicates: 0 *Warnings: 0 I really don't understand why two out of the three foreign keys get properly created while the third fails. *I do not see any significant differences in the syntax used to create them. can anyone shed light on what is going awry here, and how to fix it? Run this as well: * * * * *SHOW INNODB STATUS In practice, I've found that many foreign key errors get hidden there. Thanks, *That's a great tip - something I'd missed, but while it hi- lighted one thing I missed, the error still makes no sense. Here is the definition of the processors table (that the failed foreign key references: CREATE TABLE `processors` ( * *`p_id` int(11) NOT NULL AUTO_INCREMENT, * *`processor_name` varchar(256) NOT NULL, * *`tz_processor` varchar(26) NOT NULL DEFAULT 'GMT', * *`tz_processor_DST` varchar(45) DEFAULT 'UTC', * *`processor_name2` varchar(45) DEFAULT NULL, * *`payment_type` varchar(2) NOT NULL DEFAULT 'cc', * *PRIMARY KEY (`p_id`) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; Thus, I changed the type of p_id in my new table to be int(11) instead of int(10), but still *the error remains. *From "SHOW INNODB STATUS", the error is: "LATEST FOREIGN KEY ERROR '------------------------ "110216 13:21:27 Error in foreign key constraint of table merchants2/ #sql-1248_d: * "FOREIGN KEY (p_id) REFERENCES processors (p_id): "Cannot find an index in the referenced table where the "referenced columns appear as the first columns, or column types "in the table and the referenced table do not match for constraint. "Note that the internal storage type of ENUM and SET changed in "tables created with>= InnoDB-4.1.12, and such columns in old tables "cannot be referenced by such columns in new tables. "Seehttp://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints... "for correct foreign key definition." Obviously, the referenced column in the processors table exists, it is the first column, and it is the primary key in that table, and it is now the same tpye even to the size of the integer. It's not exactly the same type: `p_id` int(11) NOT NULL AUTO_INCREMENT, `p_id` int(10) unsigned NOT NULL, Notice the signed/unsigned difference. |
#6
| |||
| |||
|
|
On Feb 17, 5:11 am, "Álvaro G. Vicario" alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: El 16/02/2011 19:29, Ted Byers escribió/wrote: On Feb 16, 1:00 pm, "Álvaro G. Vicario" alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: El 16/02/2011 18:30, Ted Byers escribi /wrote: Here is the table I am attempting to create. DROP TABLE proc_trans_distinctions IF EXISTS; CREATE TABLE proc_trans_distinctions ( `m_id` int(10) unsigned NOT NULL, `p_id` int(10) unsigned NOT NULL, `mid` varchar(256) NOT NULL DEFAULT '0', `cc_id` int(10) unsigned NOT NULL, distinction_class TINYINT UNSIGNED NOT NULL, PRIMARY KEY (p_id,mid,cc_id) USING BTREE, CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants), CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id), CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; The tables and columns in the references clauses are correct, and the columns in question are primary keys in those tables and have the same type as the columns in the corresponding fields in this table. This produces the following error: ERROR 1005 (HY000): Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) mysql> SHOW ERRORS; +-------+------ +---------------------------------------------------------------------- + | Level | Code | Message | +-------+------ +---------------------------------------------------------------------- + | Error | 1005 | Can't create table 'merchants2.proc_trans_distinctions' (errno: 150) | +-------+------ +---------------------------------------------------------------------- + 1 row in set (0.00 sec) In the online MySQL 5.0 reference manual, I see: 13.2.12.1. InnoDB Error Codes The following is a nonexhaustive list of common InnoDB-specific errors that you may encounter, with information about why each occurs and how to resolve the problem. 1005 (ER_CANT_CREATE_TABLE) Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error 1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table. If I create the table WITHOUT the foreign keys, and then ADD the foreign keys, I get the following result: mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT m_ptd_mfk FOREIGN KEY (m_id) REFERENCES merchants (idmerchants); Query OK, 0 rows affected (0.07 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT p_ptd_pfk FOREIGN KEY (p_id) REFERENCES processors (p_id); ERROR 1005 (HY000): Can't create table 'merchants2.#sql-1248_d' (errno: 150) mysql> ALTER TABLE proc_trans_distinctions -> ADD CONSTRAINT cc_ptd_ccfk FOREIGN KEY (cc_id) REFERENCES credit_card_types (id); Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 I really don't understand why two out of the three foreign keys get properly created while the third fails. I do not see any significant differences in the syntax used to create them. can anyone shed light on what is going awry here, and how to fix it? Run this as well: SHOW INNODB STATUS In practice, I've found that many foreign key errors get hidden there. Thanks, That's a great tip - something I'd missed, but while it hi- lighted one thing I missed, the error still makes no sense. Here is the definition of the processors table (that the failed foreign key references: CREATE TABLE `processors` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `processor_name` varchar(256) NOT NULL, `tz_processor` varchar(26) NOT NULL DEFAULT 'GMT', `tz_processor_DST` varchar(45) DEFAULT 'UTC', `processor_name2` varchar(45) DEFAULT NULL, `payment_type` varchar(2) NOT NULL DEFAULT 'cc', PRIMARY KEY (`p_id`) ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; Thus, I changed the type of p_id in my new table to be int(11) instead of int(10), but still the error remains. From "SHOW INNODB STATUS", the error is: "LATEST FOREIGN KEY ERROR '------------------------ "110216 13:21:27 Error in foreign key constraint of table merchants2/ #sql-1248_d: "FOREIGN KEY (p_id) REFERENCES processors (p_id): "Cannot find an index in the referenced table where the "referenced columns appear as the first columns, or column types "in the table and the referenced table do not match for constraint. "Note that the internal storage type of ENUM and SET changed in "tables created with>= InnoDB-4.1.12, and such columns in old tables "cannot be referenced by such columns in new tables. "Seehttp://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints... "for correct foreign key definition." Obviously, the referenced column in the processors table exists, it is the first column, and it is the primary key in that table, and it is now the same tpye even to the size of the integer. It's not exactly the same type: `p_id` int(11) NOT NULL AUTO_INCREMENT, `p_id` int(10) unsigned NOT NULL, Notice the signed/unsigned difference. Ok, I missed that. |

|
Changing it to: `p_id` int(11) NOT NULL, fixes it (it had been changed to int11 before - I just didn't think about unsigned vs unsigned, or notice it). |
![]() |
| Thread Tools | |
| Display Modes | |
| |