“django.db.utils.ProgrammingError: relation ”app_user“ does not exist” during manage.py test

前端 未结 6 770
你的背包
你的背包 2020-12-10 15:02

My setup:

  • Django 1.8.3
  • Python 2.7.10
  • Ubuntu 14.04
  • django-two-factor-auth==1.2.0

I get the following error when I ru

相关标签:
6条回答
  • 2020-12-10 15:07

    You have not given any code so its difficult to understand your models relations. But can I guess that you have passed the ForeignKey model as an instance? Try to give it as a string

    class MyModel(models.Model):
        fk_field = models.ForeignKey('path.to.other.model')    # same as from path.models import model
    

    This usually works out. Hope it does for you too!

    0 讨论(0)
  • 2020-12-10 15:07

    I had a similar issue with manage.py test when I ran it in gitlab CI jobs, I was able to fix this by creating a variable called CI in my base.py settings file

    base.py

    """
    Set CI Variable to True when running: "manage.py test"
    """
    CI = True  
    

    and in my settings.py:

    if CI:
        class DisableMigrations(object):
    
            def __contains__(self, item):
                return True
    
            def __getitem__(self, item):
                return None # For Django 1.10+
    
    MIGRATION_MODULES = DisableMigrations()
    
    0 讨论(0)
  • 2020-12-10 15:10

    I've got same error beacuse one of my django applications have not migrations directory. Try to watch carefully all your apps folders which are present in INSTALLED_APPS.

    0 讨论(0)
  • 2020-12-10 15:21

    This should be solved by running:

    python manage.py migrate auth
    python manage.py migrate app
    python manage.py migrate
    
    0 讨论(0)
  • 2020-12-10 15:28

    Got the same issue, and since it happens on ./manage.py test, your migrations may be broken.
    Since Django 1.7, there is a new setting called MIGRATION_MODULES, in which you configure your app's migration modules.
    Adding the following workaround in settings.py (found here) skips migrations on tests, and solved it for me:

    class DisableMigrations(object):
    
        def __contains__(self, item):
            return True
    
        def __getitem__(self, item):
            return "notmigrations"
    
    MIGRATION_MODULES = DisableMigrations()
    
    0 讨论(0)
  • 2020-12-10 15:31
    python manage.py migrate auth
    

    This works.

    0 讨论(0)
提交回复
热议问题