id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc,focuses 44351,"Fix ""Foreign key constraint is incorrectly formed"" when running unit tests",conner_bw,,"I kept getting ""Foreign key constraint is incorrectly formed"" when running tests on my plugin. This drove me nuts for a few hours. The reason is [https://github.com/WordPress/wordpress-develop/blob/9e38c2847e5f3b94785378094d17f09577215d3c/tests/phpunit/includes/testcase.php#L335 WP_UnitTestCase::start_transaction()] The WordPress testing framework changes all 'CREATE TABLE' queries to 'CREATE TEMPORARY TABLE'. [https://dev.mysql.com/doc/refman/5.5/en/create-table-foreign-keys.html From the MYSQL manual]: > Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table. The parent and child tables must use the same storage engine. **They must not be TEMPORARY tables**. Please add something like: {{{#!php