Categories
MySQL

#1005 – Can’t create table

Full error message: #1005 – Can’t create table ‘.\my_db\#sql-7c4_444.frm’.

Using MySQL version 4.1.22-community-nt, I created two tables (`table1` and `table2`) in a database (let’s call it `my_db`) as follows:

CREATE TABLE `table1` (
`idtable1` int(10) unsigned NOT NULL auto_increment,
`table1_str` varchar(50) NOT NULL default '',
PRIMARY KEY  (`idtable1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `table2` (
`idtable2` int(10) unsigned NOT NULL auto_increment,
`idtable1_fk` int(10) NOT NULL,
`table2_str` varchar(50) NOT NULL default '',
PRIMARY KEY  (`idtable2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Then I tried to add a foreign key constraint like this:

ALTER TABLE `table2`
ADD CONSTRAINT `table2_ibfk_1` FOREIGN KEY (`idtable1_fk`) REFERENCES `table1` (`idtable1`) ON DELETE CASCADE ON UPDATE CASCADE;

And then I got the error.

The solution in my case was adding the unsigned attribute to the `idtable1_fk` field in `table2` for having the same type as the field `idtable1` it references in `table1`:

ALTER TABLE `table2` CHANGE `idtable1_fk` `idtable1_fk` int(10) unsigned NOT NULL;

After that I ran the foreign key constraint query:

ALTER TABLE `table2`
ADD CONSTRAINT `table2_ibfk_1` FOREIGN KEY (`idtable1_fk`) REFERENCES `table1` (`idtable1`) ON DELETE CASCADE ON UPDATE CASCADE;

And then it worked. But if you don’t have the same problem but you get the same error message you might already have a foreign key constraint with the given name. For example, if I run again the foreign key constraint query I will get the same error. Be careful if you use phpMyAdmin as a visual interface for MySQL, because it seems to me that it does not show us all the foreign key constraints we added to a table. If you want to see which foreign key constraints a table has, you could export the structure of that table and analyze the foreign key constraints queri(es).

Hope this works for you, too.

Conclusion: We should make sure that the possible values of the foreign key field are in the same range as the possible values of the field referenced by that foreign key and that there is no foreign key constraint with the same name as the constraint we are trying to add.

Categories
How to

How to uninstall Google Toolbar for Firefox

Problem: Because I did not use Google Toolbar (it was automatically installed when I installed Firefox), I decided to uninstall it. I selected the Uninstall option in Tools -> Add-ons -> Google Toolbar in Firefox (Disable option being grayed) and it said that the toolbar will be uninstalled the next time Firefox will restart. So I closed and started Firefox again and I got a popop window that said something like thanks for installing Google Toolbar and if I want to see the page rank for every site I visit etc. This window kept appearing until I agreed installing Google Toolbar. I also tried uninstalling the toolbar using its uninstall setting, but I kept getting the same (reversed) result.
Everytime I closed the Firefox browser window I got sure that the procees was closed (no instances of FF remained opened).
My operating system is Windows XP Professional.

The solution that worked for me consists of two simple steps:
1. I uninstalled Google Toolbar for Internet Explorer using Control Panel -> Add/Remove programs.
2. I pressed Disable (not grayed anymore) and then Uninstall buttons for Google Toolbar in Firefox Tools -> Add-ons and restarted Firefox.

And it worked! No annoying popop window anymore.