473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_nam e ....
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_pa th)
REFERENCES url(path)
...
...

FOREIGN KEY(to_domain_n ame)
REFERENCES domain(name)
...
...

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

) ENGINE=InnoDB;
Jul 23 '05 #1
3 1603
- 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 (veryLongVarcha rField(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
1555
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 multi-threaded programs, but others may who want to use my library. Most likely they'll be using a pthreads-compatible threads system. How can I best accommodate them? Presumably they will want the error object to be in per-thread storage, so to set and...
3
2435
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
9015
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
2528
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
3432
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
2364
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 questions: - As I understand it, most functions only set errno in an error case. I take this to mean, that on success, errno is not necessarily set to EOK and I would either need to set errno to EOK before calling the function in question to...
3
3390
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 access different file system
13
1937
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 succesfully. So at the beginning of my code I have something like int errsto = errno ; and just before every successful return I have errno = errsto ; Is this ok ?
22
2499
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
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.