auth_user error with Django 1.8 and syncdb / migra

2019-03-09 06:41发布

When upgrading to Django 1.8 (with zc.buildout) and running syncdb or migrate, I get this message:

django.db.utils.ProgrammingError: relation "auth_user" does not exist

One of my models contains django.contrib.auth.models.User:

user = models.ForeignKey(
    User, related_name='%(app_label)s_%(class)s_user',
    blank=True, null=True, editable=False
)

Downgrading to Django 1.7 removes the error. Do I have to include the User object differently in Django 1.8?

9条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-09 07:31

On my environment, I fix this running makemigrations on all apps that have relationship with django.contrib.auth.models:

manage.py makemigrations app_with_user_relation
manage.py migrate
查看更多
贼婆χ
3楼-- · 2019-03-09 07:37

This problem is contained by running "makemigrations" for all apps, that have not yet been migrated, i.e. apps that do not yet have an "initial_0001.py" file in their migrations directory.

This is done (in our case we use a makefile) by running for each of these apps:

manage.py makemigrations app_name

Once that is done, you can execute:

manage.py migrate

as usual.

The underlying cause for this is that for some reason

manage.py makemigrations

does not always create these initial migrations if they are not already there. And that leads to the mentioned error.

On the contrary,

manage.py makemigrations app_name

does always create them (if not already there). Unfortunately I cannot fathom the reasons for this asymmetry.

查看更多
smile是对你的礼貌
4楼-- · 2019-03-09 07:38

I also had the same issue I solved it by using these :

python manage.py migrate auth
python manage.py migrate

Then migrate does its job

查看更多
登录 后发表回答