error creating foreign key on member_id check data types
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow error creating foreign key on name (check data types) the company Business Learn more about hiring developers or posting ads with us Stack Overflow error creating foreign key on table (check data types) Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 #1452 - cannot add or update a child row: a foreign key constraint fails million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error creating foreign key up vote 0 down vote favorite I have been searching both SO and Google for this issue, but what i came up with was pretty much what my error message tells me and that's not the problem. I am using PHPMyAdmin to create relations between tables. I have this table "warehouse_product_history" with a column "from" of type int(11) NULL. I try to create a foreign key to the table "warehouses", and the query that PHPMyAdmin executes when doing so is the following ALTER TABLE `warehouse_product_history` ADD FOREIGN KEY (`from`) REFERENCES `my_db`.`warehouses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; The type of warehouses->id is int(11) NOT NULL, so that shouldn't be the problem. I've tried to change the datatype of the `from-column to int(11) NOT NULL but with the same result. I get this error message Error creating foreign key on from (check data types) mysql share|improve this question edited Feb 10 '13 at 19:41 asked Feb 10 '13 at 19:05 Anton Gildebrand 1,37063161 What specific error are you receiving? Are you receiving this on an existing populated table? Are both tables InnoDB? Have you run SHOW INNODB STATUS after trying to create the constraint? Are both columns identical? –Kermit Feb 10 '13 at 19:08 Updated the question with the error. The warehouse table is populated. warehouse_product_history isn't. I don't have permissions to show innodb status unfortunately. They are indeed identical. –Anton Gildebrand Feb 10 '13 at 19:50 Can you share the table schema for both, so that we can try? –SparKot Feb 10 '13 at 20:34 The tables can be found on this link pastebin.com/pTxg8Bzm –Anton Gildebrand Feb 10 '13 at 20:42 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted From your table schema, your columns are not
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error creating foreign key on
Search this Thread Rate Thread #1 20-Jul-2004, 03:47 jlee Awaiting Email Confirmation Join Date: Jul 2004 Posts: 9 foreign keys using phpmyadmin Hi I am creating a website and linking it to a database using php and mysql. I need to create the https://www.gidforums.com/t-3208.html databses in phpmyadmin and have decided on the structure of the tables in the database. However, http://help.atutor.ca/developer/modules.html as expected, there are foreign keys in some of the tables - does anyone know how to link the foreign key of one table into another table within phpmyadmin so the database works properly and can be queried using sql? Is it a case of using an sql command to alter the table? I would really appreciate help with this. Thanks #2 20-Jul-2004, 06:04 foreign key JdS Senior Member Join Date: Aug 2001 Location: KUL, Malaysia Posts: 3,370 Hello jlee, MySQL has foreign key support for only InnoDB tables at the moment. I don't know if this has changed since the last release I downloaded from the site. Are the tables you plan to create going to be InnoDB tables or regular MyISAM ones? __________________J de Silva GIDApp | GIDBlog | GIDForums | GIDNetwork | Learning Journal #3 20-Jul-2004, 08:14 jlee Awaiting Email Confirmation Join error creating foreign Date: Jul 2004 Posts: 9 Quote: Originally Posted by JdS Hello jlee, MySQL has foreign key support for only InnoDB tables at the moment. I don't know if this has changed since the last release I downloaded from the site. Are the tables you plan to create going to be InnoDB tables or regular MyISAM ones? Sorry - I dont know the difference between InnoDB and MyISAM tables. The tables were made in phpmyadmin and are just pretty standard tables. #4 20-Jul-2004, 16:52 JdS Senior Member Join Date: Aug 2001 Location: KUL, Malaysia Posts: 3,370 I will assume "...are just prety standard" to mean that your tables are of the type MyISAM. With a MyISAM table, there is NO data integrity check made by MySQL for foreign keys; you can set it up but it's useless. Examples usually help to explain much better, so here is an example of 3 MyISAM tables and how you normally would insert the primary key from one into another as the 'foreign key'. Code: # Create the MEMBER table CREATE TABLE `member` ( `id` int(10) unsigned NOT NULL default '0', `firstname` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM; # Create the DOMAIN table CREATE TABLE `domain` ( `id` int(10) unsigned NOT NULL default '0', `domain_name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM; # Create the MEMBER_SITES table # ----------------------------- # the 2 'foreign keys' here.. CREATE TABLE `member_sites` ( `member_id` int(10) unsigne
Executing an SQL FILE Generating Error Messages Uninstalling a Module Authentication & Privileges Localisation Configuration Options Custom Style Sheets Side Menu Boxes Sublinks for Details View Student Tools Group Tools Navigation & Hierarchy Course Deletion Module News Module Calendar Extension Custom Content Manipulation Backing-Up and Restoring Directories Database Tables Running Cron/Scheduling Introduction ATutor 1.5.2 introduced the concept of modules, providing developers with a framework to implement additional functionality in a coherent and loosely coupled way. The framework defines methods for assigning privileges, backing-up and restoring content, deleting course specific content, and adding side menu blocks, student tools, course management and administrative tools, as well as public tools and other types of added functionality . The intent is to allow for the development and distribution of modules independent of the ongoing development and release of ATutor. The module structure does allow for the creation of modules that run software that is not distributed under the GNU General Public License, but distributed separately under their own, perhaps commercial licenses. The Hello World example module is included with each ATutor distribution for developers who want to investigate how modules work. The module is found in the mods/hello_world directory. A copy of the Hello World module works well as a starting point for creating a new module, since it implements (in a simple way) just about all the features found in modules. Also see the files from other modules that operate like you expect your module to operate. Differences from pre ATutor 2.2 The primary difference in creating module for versions after, and including ATutor 2.2, is the addition of the queryDB() function. It is a database abstraction layer based of PHP's sprintf() function that replaces all previous mysql related functions. This accommodates for the use of mysql or mysqli related database queries, as well as the use of databases other than MySQL. The following simple example shows how queryDB() is used to create a database call that is equivalent to a mysql call. The output from queryDB() is an array of values equivalent to an array that would be output from mysql_fetch_assoc(). For more about using queryDB(), refer to the queryDB() section of the Developer Documentation. /////// // A mysql database query $sql = "SELECT member_id, country from ".TABLE_PREFIX."members WHERE country = '