Bug #9802 foreign key checks disallow alter table
Submitted: 11 Apr 2005 3:40 Modified: 13 Apr 2005 11:32
Reporter: Timothy Smith
Status: Closed
Category:Server: InnoDB Severity:S2 (Serious)
Version:4.1, 5.0 OS:Any (all)
Assigned to: Marko Mäkelä Target Version:

[11 Apr 2005 3:40] Timothy Smith
Description:

See the "How to repeat" section.

How to repeat:

create table validnames ( name varchar(32), primary key (name) ) type=innodb;
insert into validnames (name) values ('heikki');
create table employee ( empname varchar(32), foreign key (empname) references validnames
(name)) type=innodb;
insert into employee (empname) values ('heikki');
set foreign_key_checks=0;
alter table employee convert to character set utf8;    -- This fails
alter table employee convert to character set latin1;

Suggested fix:
Allow the ALTER TABLE, at least if foreign_key_checks is off.
[11 Apr 2005 6:47] Heikki Tuuri
Tim,

hmm..., if ...=0, we could relax the check if the new column type has a charset that is
not comparison-compatible with the referenced column or the referencing column.

If the user forgets to converts the other table, it will bring strange INSERT failures,
but will not crash the server, I think.

We cannot remove all checks in an ALTER, because that may bring crashes if the user
converts in a wrong way.

Regards,

Heikki
[11 Apr 2005 16:25] Heikki Tuuri
Reassigning this to Marko, to make sure this gets fixed in 4.1.12.
[13 Apr 2005 11:32] Marko Mäkelä
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

The fix will be included in MySQL 4.1.12 and probably 5.0.5.