473,385 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

errno: 150 situation

-
i'm getting an errno: 150 when creating a table and this is what i read
from the mysql manual:

"Both tables must be InnoDB type. In the referencing table, there must
be an index where the foreign key columns are listed as the first
columns in the same order. In the referenced table, there must be an
index where the referenced columns are listed as the first columns in
the same order. Index prefixes on foreign key columns are not supported."

I only understand the first statement. Can somebody help me decipher
what the other statements mean especially the following:

"where the referenced columns are listed as the first columns in the
same order"

"Index prefixes on foreign key columns are not supported"

i want to create this table

CREATE TABLE tablename
(
from_domain_name ....
from_url_path ...
to_domain_name...
to_url_path

PRIMARY KEY(from_domain_name, from_url_path, to_domain_name, to_url_path),

FOREIGN KEY(from_domain_name)
REFERENCES domain(name)
...
...

FOREIGN KEY(from_url_path)
REFERENCES url(path)
...
...

FOREIGN KEY(to_domain_name)
REFERENCES domain(name)
...
...

FOREIGN KEY(to_url_path)
REFERENCES url(path)
...
...

) ENGINE=InnoDB;
Jul 23 '05 #1
3 1585
- wrote:
Can somebody help me decipher
what the other statements mean especially the following:

"where the referenced columns are listed as the first columns in the
same order"
If you use a composite key for your reference, the fields must be in the
same order in both the referencing and referenced tables.

For example:

create table master (
a int not null,
b int not null,
c int not null,
primary key (a, b, c)
);

create table dependent (
x int,
y int,
z int,
foreign key (x, y, z) references master(a, b, c)
);

But if you make the foreign key reference anything other than (a,b,c),
for example (b,c,a) or (a,b) or (b,c), it can't check against the
primary key in the referenced table. You must list all the fields
listed in the primary key, and in the same order as they are listed in
that primary key definition.

You can mix up the order of the fields in the foreign key, but then they
might be comparing to the wrong fields in the primary key in the other
table:
foreign key (y, z, x) references master(a, b, c)
In this case, y validates against a, z validates against b, and x
validates against c.

What are your primary key definitions in your other tables url and
domain? Do you have compound keys in those tables, and you're trying to
reference them with single-field foreign keys?
"Index prefixes on foreign key columns are not supported"


Index prefixes are for when you have very long string fields, and you
want to index the first N characters, to help reduce the overall size of
the index data structure created. You specify the length N of the
prefix when you create the index, for example:

create index foo on myTable (veryLongVarcharField(20));

They're saying you can't use that kind of index in foreign keys, for
whatever reason.

Regards,
Bill K.
Jul 23 '05 #2
-
Bill Karwin wrote:
For example:

create table master (
a int not null,
b int not null,
c int not null,
primary key (a, b, c)
);

create table dependent (
x int,
y int,
z int,
foreign key (x, y, z) references master(a, b, c)
);


somehow i managed to solve the problem by include "INDEX(path)" in the
referenced table. this even works when i removed the TYPE=INNODB
although the manual said it must be an innodb type. will the
constraints work during runtime eventhough it can compile?
Jul 23 '05 #3
- wrote:
somehow i managed to solve the problem by include "INDEX(path)" in the
referenced table.
Aha, so the path fields in the other tables weren't indexed? That was
definitely your problem.
this even works when i removed the TYPE=INNODB
although the manual said it must be an innodb type. will the
constraints work during runtime eventhough it can compile?


The constraints will *not* work if you don't make the tables InnoDB.
When you declare a foreign key in a MyISAM table, MySQL accepts the
declaration, but does not enforce the constraint. In other words, you
_are_ permitted to insert values even if they don't occur in the
referenced table.

"In MySQL 3.23.44 and up, InnoDB tables support checking of foreign key
constraints."
http://dev.mysql.com/doc/mysql/en/ex...eign-keys.html

Regards,
Bill K.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Tobin | last post by:
In a library I am writing, I want to use an errno-like mechanism for error returns. The error would probably be represented as a struct rather than just an integer. I don't have any...
3
by: Mac | last post by:
Is it legal to declare errno after you've included errno.h? For example: #include<errno.h> .... int main (void) {
4
by: Paul Emmons | last post by:
If I am writing a function that sets errno according to a possible error condition, should it also set errno to 0 if it executes normally, or should it leave errno alone on success?
11
by: Vijay Kumar R Zanvar | last post by:
> In <pan.2004.04.22.04.06.05.969827@bar.net> "Mac" <foo@bar.net> writes: > > >Is it legal to declare errno after you've included errno.h? > > > >For example: > > > >#include<errno.h> > > >...
18
by: pete | last post by:
On my system, the following five expressions are true: (HUGE_VAL == HUGE_VAL / 2) (1 / HUGE_VAL == 0) (sqrt(HUGE_VAL) == HUGE_VAL) (sqrt(-1) == HUGE_VAL) (sqrt(-HUGE_VAL) == HUGE_VAL) and
5
by: Urs Beeli | last post by:
I have a question regarding errno. If I understand it correctly, including <errno.h> allows me to check "errno" for error values that some standard library functions may set. This brings up some...
3
by: eyalc1978 | last post by:
Hi Does someone knows what does errno 72 means I got this error when fwriting a structure and still the file is being created. I saw something on the net saying that this is caused when trying to...
13
by: Spiros Bousbouras | last post by:
Assume I'm writing a function which is going to set the value of errno if something went wrong but I also want to guarantee that errno will remain unchanged if the function completed its task...
22
by: viza | last post by:
Hi all, A quick one - since errno is a lvalue, can I do: fread( & errno, sizeof errno, 1, fp ) ? TIA viza
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.