I've tried all of the solutions from the top results for this question on Google; none of them work for my situation:

  1. doing python manage.py migrate auth before `python manage.py migrate didn't work (same error)

  2. changing all references to 'auth.User' in my models to AUTH_USER_MODEL didn't work (same error), and neither did get_user_model() (makemigrations detected no changes anyway)

  3. doing python manage.py makemigrations [app_with_user_relation] did not work either (migrations were made, but still got the same error)

  4. have deleted and recreated the database multiple times

Does anyone have any new suggestions?

I hear downgrading to Django 1.7 might work, but that is not an option for me.

If anyone is curious, the app I am trying to migrate is powerdns, from the open source package django-powerdns-manager.

Full traceback: https://dpaste.de/JdT5

The failing migration: https://dpaste.de/rfUn

Custom db router: https://github.com/mike-johnson-jr/django-powerdns-manager/blob/master/src/powerdns_manager/routers.py

  • Please post the traceback. If you get that error during a migrate call, it's likely that your app is trying to access an User object too early (for example during import time). – AKX Sep 9 at 18:02
  • Traceback posted – Mike Johnson Jr Sep 9 at 18:08
  • Cheers. What about showmigrations? Does it show the migration containing the user relation to be run? – AKX Sep 9 at 18:18
  • Answered my own question – Mike Johnson Jr Sep 9 at 18:45

Custom database router routes migrations with app label "auth" to my default database rather than my powerdns database. Because of this, powerdns is making a foreignkey reference to another database, which is not possible in neither postgresql nor mysql, only sqlite. In mysql, error will be "cannot create foreign key constraint"

You can solve this error by only using 1 database or using sqlite for both.

  • Glad you got things solved. You may want to add the fact that you have a custom router to the original question and/or the title for added google-fu. – AKX Sep 9 at 18:50

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.