No Need to Create Constraints?
am 11.06.2010 00:38:27 von Lola Lee Beno
--------------030806050908080101070107
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
I'm trying to create a database, using code generated by MySQL Workbench
5.2.21 RC. I'm running into this strange issue:
ERROR 1005 (HY000): Can't create table 'nxdb.#sql-a6_3b' (errno: 150)
Database was created using utf8 as charset, collation utf8_general_ci.
Original code generated by Workbench:
CREATE TABLE IF NOT EXISTS `nxdb`.`User_Role` (
`user_id` VARCHAR(35) NOT NULL ,
`role_id` VARCHAR(35) NOT NULL ,
PRIMARY KEY (`user_id`, `role_id`) ,
CONSTRAINT `user_id`
FOREIGN KEY (`user_id`)
REFERENCES `nxdb`.`Users` (`user_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `role_id`
FOREIGN KEY (`role_id`)
REFERENCES `nxdb`.`NXRoles` (`role_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
(Note, tables Users and NXRoles were already created). This query
didn't work. So, I stripped down to the basics to get the table created:
CREATE TABLE IF NOT EXISTS `nxdb`.`User_Role` (
`user_id` VARCHAR(35) NOT NULL ,
`role_id` VARCHAR(35) NOT NULL ,
PRIMARY KEY (`user_id`, `role_id`) )
ENGINE = InnoDB;
Then, I tried running this:
ALTER TABLE `User_Role` ADD
CONSTRAINT `role_id`
FOREIGN KEY (`role_id`)
REFERENCES `NXRoles` (`role_id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
And got this error message: ERROR 1005 (HY000): Can't create table
'nxdb.#sql-a6_3b' (errno: 150)
When I check the structure of User_Role in phpMyAdmin (couldn't see a
way to do this in Workbench), this is what I'm seeing:
Action Keyname Type Unique Packed Field Cardinality
Collation Null Comment
PRIMARY BTREE Yes No user_id 0 A
role_id 0 A
So, is there no need for me to actually add these constraints?
--
Lola J. Lee Beno
LinkedIn: http://www.linkedin.com/in/lolajleebeno
Facebook: http://www.facebook.com/profile.php?id=714355583
Blog: http://www.lolajl.net/blog/
--------------030806050908080101070107--
Re: No Need to Create Constraints?
am 11.06.2010 02:05:46 von shawn.l.green
On 6/10/2010 6:38 PM, Lola Lee Beno wrote:
> I'm trying to create a database, using code generated by MySQL Workbench
> 5.2.21 RC. I'm running into this strange issue:
>
> ERROR 1005 (HY000): Can't create table 'nxdb.#sql-a6_3b' (errno: 150)
>
>
> Database was created using utf8 as charset, collation utf8_general_ci.
>
> Original code generated by Workbench:
>
> CREATE TABLE IF NOT EXISTS `nxdb`.`User_Role` (
> `user_id` VARCHAR(35) NOT NULL ,
> `role_id` VARCHAR(35) NOT NULL ,
> PRIMARY KEY (`user_id`, `role_id`) ,
> CONSTRAINT `user_id`
> FOREIGN KEY (`user_id`)
> REFERENCES `nxdb`.`Users` (`user_id`)
> ON DELETE NO ACTION
> ON UPDATE NO ACTION,
> CONSTRAINT `role_id`
> FOREIGN KEY (`role_id`)
> REFERENCES `nxdb`.`NXRoles` (`role_id`)
> ON DELETE CASCADE
> ON UPDATE CASCADE)
> ENGINE = InnoDB;
>
> (Note, tables Users and NXRoles were already created). This query
> didn't work. So, I stripped down to the basics to get the table created:
>
> CREATE TABLE IF NOT EXISTS `nxdb`.`User_Role` (
> `user_id` VARCHAR(35) NOT NULL ,
> `role_id` VARCHAR(35) NOT NULL ,
> PRIMARY KEY (`user_id`, `role_id`) )
> ENGINE = InnoDB;
>
> Then, I tried running this:
>
> ALTER TABLE `User_Role` ADD
> CONSTRAINT `role_id`
> FOREIGN KEY (`role_id`)
> REFERENCES `NXRoles` (`role_id`)
> ON DELETE CASCADE
> ON UPDATE CASCADE;
>
> And got this error message: ERROR 1005 (HY000): Can't create table
> 'nxdb.#sql-a6_3b' (errno: 150)
>
> When I check the structure of User_Role in phpMyAdmin (couldn't see a
> way to do this in Workbench), this is what I'm seeing:
>
> Action Keyname Type Unique Packed Field Cardinality
> Collation Null Comment
> PRIMARY BTREE Yes No user_id 0 A
> role_id 0 A
>
>
> So, is there no need for me to actually add these constraints?
>
For more details about the error 150 code, check the SHOW ENGINE INNODB
STATUS report.
--
Shawn Green
MySQL Principle Technical Support Engineer
Oracle USA, Inc.
Office: Blountville, TN
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: No Need to Create Constraints?
am 11.06.2010 19:55:02 von jayabharath
--000e0cd25b7c9e4ca90488c4d6c9
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
I got the below information from a website, when I encountered this error.
Hope this would be helpful for you.
In every case this is due to something about the relationship that MySQL
doesn=92t like. Unfortunately it doesn=92t specify what the exact issue is.=
Here
is a running list of causes that people have reported for the dreaded* **er=
rno
150. *I=92ve 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 =93SHOW ENGINE INNODB
STATUS=94 immediately after receiving the error. This command displays log
info and error details.
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=92t 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 signe=
d
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 field.
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.
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=92t get an error message =96 it just won=92t 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.
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.
7. You have a default value (ie default=3D0) on your foreign key column
8. One of the fields in the relationship is part of a combination
(composite) key and does not have it=92s 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.
9. You have a syntax error in your ALTER statement or you have mistyped one
of the field names in the relationship
10. The name of your foreign key exceeds the max length of 64 chars.
Regards,
Jayabharath.J
MySQL DBA,
Datavail Corp.
On Fri, Jun 11, 2010 at 5:35 AM, SHAWN L.GREEN wr=
ote:
> On 6/10/2010 6:38 PM, Lola Lee Beno wrote:
>
>> I'm trying to create a database, using code generated by MySQL Workbench
>> 5.2.21 RC. I'm running into this strange issue:
>>
>> ERROR 1005 (HY000): Can't create table 'nxdb.#sql-a6_3b' (errno: 150)
>>
>>
>> Database was created using utf8 as charset, collation utf8_general_ci.
>>
>> Original code generated by Workbench:
>>
>> CREATE TABLE IF NOT EXISTS `nxdb`.`User_Role` (
>> `user_id` VARCHAR(35) NOT NULL ,
>> `role_id` VARCHAR(35) NOT NULL ,
>> PRIMARY KEY (`user_id`, `role_id`) ,
>> CONSTRAINT `user_id`
>> FOREIGN KEY (`user_id`)
>> REFERENCES `nxdb`.`Users` (`user_id`)
>> ON DELETE NO ACTION
>> ON UPDATE NO ACTION,
>> CONSTRAINT `role_id`
>> FOREIGN KEY (`role_id`)
>> REFERENCES `nxdb`.`NXRoles` (`role_id`)
>> ON DELETE CASCADE
>> ON UPDATE CASCADE)
>> ENGINE =3D InnoDB;
>>
>> (Note, tables Users and NXRoles were already created). This query didn'=
t
>> work. So, I stripped down to the basics to get the table created:
>>
>> CREATE TABLE IF NOT EXISTS `nxdb`.`User_Role` (
>> `user_id` VARCHAR(35) NOT NULL ,
>> `role_id` VARCHAR(35) NOT NULL ,
>> PRIMARY KEY (`user_id`, `role_id`) )
>> ENGINE =3D InnoDB;
>>
>> Then, I tried running this:
>>
>> ALTER TABLE `User_Role` ADD
>> CONSTRAINT `role_id`
>> FOREIGN KEY (`role_id`)
>> REFERENCES `NXRoles` (`role_id`)
>> ON DELETE CASCADE
>> ON UPDATE CASCADE;
>>
>> And got this error message: ERROR 1005 (HY000): Can't create table
>> 'nxdb.#sql-a6_3b' (errno: 150)
>>
>> When I check the structure of User_Role in phpMyAdmin (couldn't see a wa=
y
>> to do this in Workbench), this is what I'm seeing:
>>
>> Action Keyname Type Unique Packed Field Cardinality
>> Collation Null Comment
>> PRIMARY BTREE Yes No user_id 0 A
>> role_id 0 A
>>
>>
>> So, is there no need for me to actually add these constraints?
>>
>>
> For more details about the error 150 code, check the SHOW ENGINE INNODB
> STATUS report.
>
> --
> Shawn Green
> MySQL Principle Technical Support Engineer
> Oracle USA, Inc.
> Office: Blountville, TN
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=3Djbharathj@gmail.c=
om
>
>
--000e0cd25b7c9e4ca90488c4d6c9--