Why do I get a “auth_user does not exist”error when running “migrate” on a newly created django project with “registration redux” app installed?

前端 未结 6 1474
小鲜肉
小鲜肉 2021-02-20 10:57

Given a newly created django project with the following installed apps:

INSTALLED_APPS = (
\'django.contrib.admin\',
\'django.contrib.auth\',
\'django.contrib.co         


        
相关标签:
6条回答
  • 2021-02-20 11:38

    Once you create a migration for your app it will automatically add the necessary dependencies. So in this case just run ./manage.py makemigrations registration.

    Please check the registration/migrations/0001_initial.py file and you should see something like this:

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]
    

    This means you need to create migrations for all your apps with any kind of dependency.

    0 讨论(0)
  • 2021-02-20 11:39

    I had this problem too, solved it by replacing old registration with one that includes pull #25:

    pip install git+https://github.com/macropin/django-registration.git@v1.2c0
    
    0 讨论(0)
  • 2021-02-20 11:42

    The problem is avoided when you do as Pedro Wagner suggests (auth_user error with Django 1.8 and syncdb / migrate):

    Make sure that for all your apps, there exist initial migrations files by running:

    manage.py makemigrations my_app
    

    I'd do it not only for those that depend on auth because I think the problem is more general.

    The root cause for this behaviour seems to me that for some reason

    manage.py makemigrations
    

    does not always create the initial migrations if they are not already there, contrary to:

    manage.py makemigrations my_app
    

    Unfortunately I cannot fathom the reasons for this asymmetry.

    0 讨论(0)
  • 2021-02-20 11:42

    you have not migrated your models

    python manage.py makemigrations my_app_name

    for mac os

    python3 manage.py makemigrations my_app

    0 讨论(0)
  • 2021-02-20 11:47

    I think you needed to run:

    python manage.py syncdb

    and potentially you need to setup some dependencies? Probably not necessary after syncdb.

    South 1 style (Django < 1.7)

    class Migration:
    
        depends_on = (
            ("accounts", "0001"),
        )
    
        def forwards(self):
            ....
    

    South 2 style (Django >= 1.7)

    from django.db import migrations, models
    
    class Migration(migrations.Migration):
    
        dependencies = [("accounts", "0001")]
    
    0 讨论(0)
  • 2021-02-20 11:56

    After updating my Django version, I got this error and fix as running these two lines:

    python manage.py migrate auth
    python manage.py migrate
    

    auth_user table inside auth model should run first I guess.

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