xpanta
xpanta

Reputation: 8418

Django: I get a [relation "auth_group" does not exist] error after syncdb

I started a new Django 1.8 project and realized that I missed something (i had done the initial migrations). I dropped the database (postgreSQL) and deleted migration folders from all my apps in order to start from scratch.

Now, when I 'syncdb' I get this error:

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

and when I makemigrations I get this:

No changes detected

What am I doing wrong?

Upvotes: 15

Views: 15957

Answers (8)

F.M.F.
F.M.F.

Reputation: 2300

I tried all the solutions here, but nothing helped. Finally I commented out all the apps I created in INSTALLED_APPS, then called python manage.py makemigrations and python manage.py migrate for the remaining apps (like auth). Then I added my apps back one by one and called python manage.py makemigrations and python manage.py migrate again after each app.

This worked for me.

Upvotes: 0

Mark Anthony Libres
Mark Anthony Libres

Reputation: 1054

One of your paths ("pointing urls.py on your core folder along with the settings.py") makes that problem occur importing django.contrib.auth and directly using methods and properties of "auth" after calling those views

  • Remove all migrations except "init.py" of each apps
  • Go to projects urls.py and comment out all the paths
  • run "heroku run python manage.py makemigrations"
  • run "heroku run python manage.py migrate"

Upvotes: 0

Hashim
Hashim

Reputation: 95

I had the similar problem with Django2.2 migrations. I will post what helped in case someone is looking to fix this.

I commented out all urls to apps(like my_app.urls, your_app.urls) in main project urls.py and then ran makemigrations, it worked. I think this error is due to some forms/views referring to model/fields that are not yet created. It seems django traverses urls.py to before making migrations

Upvotes: 1

tmin
tmin

Reputation: 1323

It can be either:

  • one of the pip dependencies from requirements.txt was using South

    had this error when running tests which do migration in Django 1.8. Found the lib with issue by running tests in verbose mode. Consider upgrading the library to newer version.

manage.py test -v 3

  • one of the /migrations folder might still has old South migrations files. It can be because others are still adding migrations when you are trying to upgrade Django. Use the following to make sure that the expected migrations files are present in each app.

manage.py showmigrations

Upvotes: 0

Aminah Nuraini
Aminah Nuraini

Reputation: 19186

The problem is on no changes detected. Please execute these commands with your app name. I guess you didn't add it (just like the mistake I did):

  1. python manage.py makemigrations myappname
  2. python manage.py migrate myappname

Upvotes: 9

James Hiew
James Hiew

Reputation: 7157

Doing ./manage.py migrate auth first didn't work for me, and every ./manage.py command was throwing this error. My problem was that I was doing stuff with the Group manager in module scope.

If you have code like this in module scope:

customers_group = Group.objects.get(name='customers')

Move it inside a function that is called at runtime instead.

def xyz():
    ...
    customers_group = Group.objects.get(name='customers')

Upvotes: 5

Maurice Elagu
Maurice Elagu

Reputation: 704

The above error occurs when you have django.contrib.admin among the installed applications. Run these commands in their respective order.

**

./manage.py makemigrations 
./manage.py migrate auth
./manage.py migrate**

That worked for me perfectly.

Upvotes: 4

Ihor Pomaranskyy
Ihor Pomaranskyy

Reputation: 5641

Probably you should try to create migrations modules (folders named migrations with empty file named __init__.py inside of each directory) for your apps. And then run manage.py makemigrations again.

Upvotes: 35

Related Questions