pinax / django-user-accounts

User accounts for Django
MIT License
1.22k stars 356 forks source link

Error running tests with Django 1.8.2: relation "auth_user" does not exist #179

Closed kutenai closed 8 years ago

kutenai commented 9 years ago

I updated my project from 1.7.x to 1.8.2, and tests failed with the above issue. I've tried a number of solutions to fix this, and I did narrow it down to django-user-accounts. When I comment that project out, things work.

I reverted back to Django 1.7.6, and the tests work fine. I was unable to find any references to that error related to django-user-accounts, but I did find references related to other projects that seem to say that a migration is required. This project currently has no migrations. That is just a wild guess on my part..

This project claims support for Django 1.8, so I'm confused about why I'm getting this error, and others are not.

john2x commented 9 years ago

Getting the same issue as well with 1.8, although this is for a new project (no existing migrations, etc.). manage.py migrate only succeeds when the "account" app is removed.

EDIT:

This seems to work, run migrate auth first, which fails, and then migrate succeeds:

$ ./manage.py migrate auth
... # fails with
django.db.utils.ProgrammingError: relation "django_site" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1
                               ^
$ ./manage.py migrate
... OK

Although it's just a workaround and doesn't solve the real issue.

mattions commented 9 years ago

If you create a project using django 1.8.2 django.contrib.sites is not automatically included in your installed app and it's a needed dependencies: http://django-user-accounts.readthedocs.org/en/latest/installation.html#django-contrib-sites

the fix is quick: add django.contrib.sites to your INSTALLED_APPS

for reference:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites'
)

and run the migrate command

john2x commented 9 years ago

For my case, I already have django.contrib.sites in the project.

mattions commented 9 years ago

did you run python manage.py migrate ? The table should be created by that.

john2x commented 9 years ago

ah running python manage.py migrate fails because of the "account" app, so I need to do python manage.py migrate auth first, which fails but is another issue with regards to sites app I guess.

EDIT: err wait, let me try again later with a fresh database.

meleksomai commented 9 years ago

Any solution for this issue? I'm still having the same problem. Would be great to have a fix.

brosner commented 9 years ago

I will be looking at this issue today.

ravigadila commented 9 years ago

Hi, any body got solution? same problem for me.

$python manage.py migrate django.db.utils.ProgrammingError: relation "auth_user" does not exist $python manage.py migrate auth django.db.utils.ProgrammingError: relation "django_site" does not exist LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1

brosner commented 9 years ago

@ravigadila can you post your INSTALLED_APPS?

ravigadila commented 9 years ago

@brosner

INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'djangocms_admin_style', 'django.contrib.admin', 'django_extensions', 'django_model_changes', 'django_messages', 'userena', 'guardian', 'easy_thumbnails', 'mathfilters', 'crispy_forms', 'accounts', 'paypal.standard.ipn', 'loans', 'messaging', 'rest_framework', 'rest_framework.authtoken', )

brosner commented 9 years ago

I am having a hard time reproducing this problem. What database are you using @ravigadila?

ma1onso commented 8 years ago

Same problem Postgresql database

Amar-Chaudhari commented 8 years ago

Kind of same problem -

Applying admin.0001_initial...Traceback (most recent call last): File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) psycopg2.ProgrammingError: relation "main_myuser" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/core/management/init.py", line 354, in execute_from_command_line utility.execute() File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/core/management/init.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/core/management/base.py", line 394, in run_from_argv self.execute(_args, _cmd_options) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/core/management/base.py", line 445, in execute output = self.handle(_args, _options) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 222, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/migrations/executor.py", line 110, in migrate self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/migrations/executor.py", line 148, in apply_migration state = migration.apply(state, schema_editor) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 91, in exit self.execute(sql) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 111, in execute cursor.execute(sql, params) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/utils.py", line 98, in exit six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise raise value.with_traceback(tb) File "/Users/amarchaudhari/Documents/gaurav_project/fit/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: relation "main_myuser" does not exist

brosner commented 8 years ago

I don't like how so many people have commented on this issue saying they have an issue, but I cannot reproduce it. I really want to find a fix for what's going on. If anyone has a project where this is easily reproducible, could you share it with me? I suspect there is something going on that is hidden in the project.

@john2x: you seem to be my only hope as you claim you can reproduce this with a fresh started project. Are you still able to reproduce this issue?

paltman commented 8 years ago

What version of DUA are people using that are experiencing this issue? I have not been able to reproduce this problem with 1.2 in both scenarios -- upgrading from 1.7 to 1.8 or starting fresh with 1.8.

jeymichael commented 8 years ago

I narrowed this down to switching to postgres DB, at least in my case. The project works on sqlite, but when switched to postgres, this error pops up. This breaks the whole test /infrastructure process.

brosner commented 8 years ago

@jeymichael I have tested against both SQLite and PostgreSQL. Which version of PostgreSQL are you running?

jeymichael commented 8 years ago

Postgres 9.4.5.0

jeymichael commented 8 years ago

$ cat requirements.txt Django==1.8.6 djangorestframework==3.3.1 psycopg2==2.6.1 requests==2.8.1 wheel==0.24.0

jeymichael commented 8 years ago

Brian, I have the archived project as well, if you need it.

brosner commented 8 years ago

@jeymichael thanks for the info. I am going to start a project using those exact requirements and versions. I'll let you know if I need it.

brosner commented 8 years ago

@jeymichael are you on our Pinax Slack instance? It'd be really helpful for me if you joined the #django-user-accounts channel and we can talk there. http://slack.pinaxproject.com to join.

brosner commented 8 years ago

I have finally figured out what is likely happening here. With the help of @jeymichael I was able to track down the exception. Jey wasn't using django-user-accounts, but his test project showed me the issue.

Our 1.0.x releases did not have Django migrations. Due to the lack of migrations (largely due to the development of DUA prior to its 1.0 release was pre-1.7) and django.contrib.auth gaining migrations in Django 1.7 this has caused a dependency issue. I don't know exactly why it worked in 1.7 and fails on 1.8. The issue is that an app without migrations that depends on an app with migrations most likely won't be handled correctly. Apps without migrations are created in the database before apps with migrations. Meaning because django-user-accounts depends on django.contrib.auth.User it was being sync'd to the database when auth_user didn't exist.

1.1+ of django-user-accounts contain migrations and will solve this issue for those affected.

leonardocintra commented 8 years ago

This error also occurred in Django 1.9 I ran the following command and it worked $ ./manage.py migrate auth

:+1:

amitt001 commented 8 years ago

Getting the same error.

python manage.py makemigrations auth

No changes detected in app 'auth'

In [1]: from django.contrib.auth.models import User In [2]: user = User.objects.create_user('test', 'test@test.com', 'testpass' )

ProgrammingError: relation "auth_user" does not exist LINE 1: INSERT INTO "auth_user" ("password", "last_login", "is_super...

Django 1.9.2 DB: Postgresql INSTALLED_APPS = [

'django.contrib.admin',

'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'execute',

]

mwaz commented 6 years ago

The still also persists in Django v.1.11 @brosner (been navigation through fixes and none is present for this one) With the following installed apps

INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.humanize', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',

screen shot 2018-01-11 at 20 27 39
heidihoge commented 6 years ago

None of those commands resolved this issue (Django 2). I deleted my database and migrate again :/ , that's do worked haha

abu-yusuf-dev commented 5 years ago

Just delete the existing data and create a new one, then try ./manage.py migrate

bazokizo commented 5 years ago

@Revel109 ive done that and still getting this error when deploying to heroku

ProgrammingError at / relation "posts_post" does not exist LINE 1: ...evious_post_id", "posts_post"."next_post_id" FROM "posts_pos... ^

memetics19 commented 4 years ago

I think it's been appearing in the django-2.2 version also

Bharath95 commented 4 years ago

I see it in django-3.0 as well, with postgres.

sjtly16 commented 4 years ago

hey, I have found the reason for this issue. It pops with relation "auth_user" does not exist whenever we try to reference to User from django.contrib.auth.models before building our first auth migrations. So the solution for this that worked for me was Commenting out any reference to the User model and then running the migrations, later you can uncomment User model references and run new migrations.

memetics19 commented 4 years ago

@ShashankJaitly I think, it's not a good practice to do it. DUA really resolved this issue in later stage but the django updated the version recently, May be it's not depreciated yet.

sjtly16 commented 4 years ago

@memetics19 Yes, you may right. But I recently got this issue while working on Django 3.0.6 and I managed to get through it just like I mentioned in my last comment, and it worked fine.

rashabeka commented 1 year ago

i got the same issu using cassandra (django version 4.1.7 )> Any suggestions ?

uhurusurfa commented 1 year ago

@rashabeka - make sure you have run all the migrations for the apps you are using