Django: "Cannot add foreign key constraint"

Upgraded to Django 1.8 and now you get this error when you run your tests? Have you created migrations for all your apps? If not, you may well be hitting the problem that the database tables are being created in the wrong order, which will give you this error. If you have an existing Django 1.7 or earlier project, then you need to create the initial migration files, and then fake the initial migration, as described here


SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST; gives the same info (in recent MySqls) and can be filtered;

checking for duplicates

if for example, you want to apply a unique index, but you can’t because there’s duplicates in the table. SELECT name FROM mytable GROUP BY name HAVING COUNT(*) > 1;