There is a six years old issue which has a working patch: https://code.djangoproject.com/ticket/10827
If a migration deletes and recreates content-types, then the automatically called create_migrations()
can result in ForeignKey constraint errors.
If Permission "Can add group" had primary key 1 before the migration and after the migration
it has the value 2, then things get broken.
The cache needs to be cleared first.
Please have a look at it.