0

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

4
  • 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). Commented Sep 9, 2018 at 18:02
  • Traceback posted Commented Sep 9, 2018 at 18:08
  • Cheers. What about showmigrations? Does it show the migration containing the user relation to be run? Commented Sep 9, 2018 at 18:18
  • Answered my own question Commented Sep 9, 2018 at 18:45

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.