1

after a long time procrastinating I decided to upgrade my django app from 1.7.11 to 1.8.13 (due to its LTS). Everything went fine and after fixing some clear errors (I needed to upgrade to django-mptt==0.8.4 and django-filter==0.13.0 alongside with Django==1.8.13) and deleting some conflicting field attributes, I maganed to run my server properly.

Apparently my app works fine (I test the website manually, performing 2-3 actions and I see no clear error).

However, when running the tests (with ./manage.py test -v 3), I get the following output:

[...]
Running pre-migrate handlers for application debug_toolbar
  Creating tables...
    Creating table corsheaders_corsmodel
    Creating table actstream_follow
    Creating table actstream_action
    Creating table thumbnail_kvstore
    Creating table django_comments
    Creating table django_comment_flags
    Creating table tagging_tag
    Creating table tagging_taggeditem
    Creating table blog_newslettersubscription
    Running deferred SQL...
Traceback (most recent call last):
  File "/home/user/workspace/project/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "app_user" does not exist.

The app app is where I have my AUTH_USER_MODEL, i.e in my settings.py:

AUTH_USER_MODEL = 'app.User'

and in my app/models.py:

class User(AbstractBaseUser):
    [...]

I have read a lot of questions like this, this, this, this and also this. and I have searched a lot, but I can't find an solution to my problem (none of them worked).

The weird thing is that if I check the database (Postgresql), the table exists. Executing:

SELECT relname, reltuples, relpages * 8 / 1024 AS "MB" FROM pg_class ORDER BY relpages DESC;

returns:

                             relname                    |  reltuples  |  MB   
...                                                     |             |
app_user                                                |        4034 |     0
...                                                     |             |

Any clues? Any help would be much appreciated! Thanks in advance.

Update: My INSTALLED_APPS:

INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.gis',
    'crispy_forms',
    'rosetta',
    'django_extensions',
    'django_slack',
    'filebrowser',
    'mptt',
    'corsheaders',
    'actstream',
    'compressor',
    'sorl.thumbnail',
    'geoposition',
    'reversion',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_framework_swagger',
    'rest_auth',
    'django_comments',
    'tagging',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'rest_auth.registration',
    'import_export',
    'oauth2_provider',
    'places',
    'tasks',
    'transmeta',
    'app',
)
Community
  • 1
  • 1
vabada
  • 1,738
  • 4
  • 29
  • 37
  • post your INSTALLED_APPS please – e4c5 Jun 23 '16 at 12:16
  • Now added. Thanks! – vabada Jun 23 '16 at 12:38
  • I've managed to run the tests, but by taking out some of the apps. Exactly the following: `actstream`, `django_comments`, `tagging`, `allauth`, `allauth.account`, `allauth.socialaccount`, `allauth.socialaccount.providers.facebook`. If I keep any of them I have the problem shown in the question, but with them tests run and only three don't pass (not related to these apps). So I got a solution but I'm not sure of the implications of this (since I got this project from other people and I don't know exactly what are these apps used for (even if they are used). – vabada Jun 24 '16 at 09:40
  • Any way (apart from searching through the project) to know whether these apps are actually used and if there is some consequence by deleting them? – vabada Jun 24 '16 at 09:41
  • There is no reason for you to test any of those apps listed. They are third party apps. Well you can test them if you want to but that's a job for the authors of those apps. – e4c5 Jun 27 '16 at 07:15
  • I understand that. It's just that as part of my `INSTALLED_APPS`, they are loaded when tests run. I don't test them myself, just got stuck by running my own apps' tests – vabada Jun 27 '16 at 07:34
  • 1
    Hang on a second, I think I just spotted it – e4c5 Jun 27 '16 at 07:36

2 Answers2

1

It seems like 'app' is missing from your INSTALLED_APPS, so the table doesn't get created when the test database is initialized.

Daniel Hepper
  • 28,981
  • 10
  • 72
  • 75
1

Let's take another look at your error, particularly this bit:

   Creating table blog_newslettersubscription
    Running deferred SQL...
Traceback (most recent call last):
  File "/home/user/workspace/project/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "app_user" does not exist.

This says, your blog app refers to table in your app thus app should precede blog in your settings.py

Modify your INSTALLED_APPS as follows

INSTALLED_APPS = (
   'grappelli',
   ...
   'transmeta',
   'app','blog')
e4c5
  • 52,766
  • 11
  • 101
  • 134
  • I did this (updated the answer with the INSTALLED_APPS) but no success – vabada Jun 23 '16 at 12:57
  • The table exists in both databases (I actually restored a dump locally before trying to upgrade). And all migrations are created. Only one has been created since the update of Django, related to ManyToManyFields' `null=True` that have been deleted and one in the `user` model: `migrations.AlterField( model_name='user', name='groups', field=models.ManyToManyField(...) )` I guess done by Django itself – vabada Jun 23 '16 at 13:10
  • The thing is, even though the table exists both in production and local environments, the problem happens when I run the test command (which creates a new database prefixed with `test_`) so I am a bit lost now – vabada Jun 23 '16 at 13:27
  • Sorry for that. I was confusing `test` with `development` environment. I was refering to `development`. The table was not being created in the `test` environment and hence the command didn't run. Thanks! – vabada Jun 27 '16 at 07:05
  • I find 61 migration files. 60 of which were running properly with Django 1.7. One was created when updating Django (deleting `null=True` from ManyToManyField(s) and correcting some other warnings that runserver gave me). So my `development` test is fine (as I said `runserver` works well), so I guess the order of the migrations may be wrong. – vabada Jun 27 '16 at 07:37
  • Thanks! I tried, and it works. But if I readd the `allauth` app I still get the same error with another table: `Creating table blog_newslettersubscription` passes, but if fails when `Creating table allauth_socialtoken` , and now I notice I need the `allauth` app – vabada Jun 27 '16 at 09:33
  • yes, you would need it, the order the apps are added to INSTALLED_APPS is important. – e4c5 Jun 27 '16 at 09:35
  • allauth, allauth.account and allauth.socialaccount have to be after django.contrib.sites all these should be before app and blog – e4c5 Jun 27 '16 at 09:38
  • Sorry, an incidence occured and I've been (an I am) focused in solving it. As soon as I can try it I'll let you know, but I have a good feeling :). Thanks! – vabada Jun 29 '16 at 16:29
  • I finally managed to run the tests with the allauth application included. Your hints and updating to `django-allauth==0.25.2` did the trick. Now I can move forward (just three tests to fix) and I'll be done. Thank you really much for your support! – vabada Jul 03 '16 at 10:16
  • glad to have helped – e4c5 Jul 03 '16 at 10:33