[Fixed]-Failing to migrate a foreign key from one model to another


You’re possibly running into this bug. In this case it means that you’ll have to delete the constraint before dropping the foreign key. As a short term fix you can try to do this manually by following this answer.



Not exactly this error no but, I was having a very similar error:

django.db.utils.OperationalError: (1025, 'Error on rename of ... (errno: 150 Foreign key constraint is incorrectly formed

Dropping foreign key didn’t solve my problem. However, I figured out that is a charset error. So, if you have this error probably you are trying to create new table with a different charset. So, setting default charset collation across the database solved my issue. In my case, I had error on django unit test db so;

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': env('DB_NAME'),
        'USER': env('DB_USERNAME'),
        'PASSWORD': env('DB_PASSWORD'),
        'HOST': env('DB_HOST'),
        'PORT': '',
        'TEST': {
            'CHARSET': 'latin1',
            'COLLATION': 'latin1_swedish_ci',


this configuration worked.


Leave a comment