Jump to content

Recommended Posts

mysql> CREATE TABLE LOCATION

    -> (LOC_ROW INT(2) NOT NULL,

    -> LOC_COLUMN CHAR(1) NOT NULL);

Query OK, 0 rows affected (0.05 sec)

 

mysql> CREATE TABLE SHOE

    -> (SHOE_UPC INT(18) PRIMARY KEY,

    -> SHOE_COLOR CHAR( 8) ,

    -> SHOE_TYPE CHAR(12),

    -> SHOE_MATERIAL VARCHAR(16),

    -> DESIGN_ID INT(3),

    -> LOC_ROW INT(2),

    -> LOC_COLUMN CHAR(1),

    -> FOREIGN KEY (DESIGN_ID) REFERENCES DESIGNER (DESIGN_ID),

    -> FOREIGN KEY (LOC_ROW) REFERENCES LOCATION (LOC_ROW),

    -> FOREIGN KEY (LOC_COLUMN) REFERENCES LOCATION (LOC_COLUMN));

ERROR 1005 (HY000): Can't create table './easad/SHOE.frm' (errno: 150)

Link to comment
https://forums.phpfreaks.com/topic/218963-foreign-key-not-working-in-table/
Share on other sites

Did you check that both INT columns in both tables have exactly the same sign also?

 

also... are both tables are using the Innodb engine?

 

are the columns indexed ?

 

you can also use SHOW ENGINE INNODB STATUS to display a detailed explanation of the most recent InnoDB foreign key error in the server.

 

here also you can read all the neccesary to detect any condition that could be causing that error.

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

Users will not mark their post as being "URGENT" by either making the post ALL CAPS or adding any hint that they need it done Quick or ASAP. All posts are treated equal' date=' your post is no more important than any other user's post on this forum. If it is "URGENT" pay someone to do it.[/quote']

 

I am using InnoDB

When I just use one foreign key it works (the designer one) but when i put the LOCATION table foreign keys it doesn't work

The location table was working fine too.

mysql> DESCRIBE LOCATION;
+------------+---------+------+-----+---------+-------+
| Field      | Type    | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| LOC_ROW    | int(2)  | YES  |     | NULL    |       | 
| LOC_COLUMN | char(1) | YES  |     | NULL    |       | 
+------------+---------+------+-----+---------+-------+
2 rows in set (0.01 sec)


mysql> CREATE TABLE SHOE
    -> (SHOE_UPC INT(18) PRIMARY KEY,
    -> SHOE_COLOR CHAR(,
    -> SHOE_TYPE CHAR(12),
    -> SHOE_MATERIAL VARCHAR(16),
    -> LOC_ROW INT(2),
    -> LOC_COLUMN CHAR(1),
    -> DESIGN_ID INT(3),
    -> FOREIGN KEY (DESIGN_ID) REFERENCES DESIGNER (DESIGN_ID)
    -> FOREIGN KEY (LOC_ROW) REFERENCES LOCATION (LOC_ROW)
    -> FOREIGN KEY (LOC_COLUMN) REFERENCES LOCATION (LOC_COLUMN));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (LOC_ROW) REFERENCES LOCATION (LOC_ROW)
FOREIGN KEY (LOC_COLUMN) REF' at line 10

When i put 3 foreign keys it doesn't work.

Sorry, I forgot to put the comma in but still it gets me errors...

Okay it has something to do with LOCATION probably....

mysql> CREATE TABLE SHOE
    -> (SHOE_UPC INT(18) PRIMARY KEY,
    -> SHOE_COLOR CHAR(,
    -> SHOE_TYPE CHAR(12),
    -> SHOE_MATERIAL VARCHAR(16),
    -> LOC_ROW INT(2),
    -> LOC_COLUMN CHAR(1),
    -> DESIGN_ID INT(3),
    -> FOREIGN KEY (LOC_ROW) REFERENCES LOCATION (LOC_ROW),
    -> FOREIGN KEY (LOC_COLUMN) REFERENCES LOCATION (LOC_COLUMN));
ERROR 1005 (HY000): Can't create table './easad/SHOE.frm' (errno: 150)


I bet that you didn't read this question in my last post:

are the columns indexed ?
  (table location)

 

I don't see in the CREATE TABLE LOCATION that was originally posted any INDEX definition.

 

please read:

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

 

 

You mean like this??

 

mysql> CREATE TABLE SHOE
    -> (SHOE_UPC INT(18) PRIMARY KEY,
    -> SHOE_COLOR CHAR(,
    -> SHOE_TYPE CHAR(12),
    -> SHOE_MATERIAL VARCHAR(16),
    -> LOC_ROW INT(2),
    -> LOC_COLUMN CHAR(1),
    -> DESIGN_ID INT(3),
    -> INDEX (LOC_ROW),
    -> FOREIGN KEY (LOC_ROW) REFERENCES LOCATION (LOC_ROW),
    -> INDEX (LOC_COLUMN),
    -> FOREIGN KEY (LOC_COLUMN) REFERENCES LOCATION (LOC_COLUMN),
    -> FOREIGN KEY (DESIGN_ID) REFERENCES DESIGNER (DESIGN_ID));
ERROR 1005 (HY000): Can't create table './easad/SHOE.frm' (errno: 150)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.