2

I am working on a small pet project. Everything seemed fine until I committed all my work to a git repository and cloned it in a new location.

I have set up a new virtual environment with all the modules I am using and here my surprise: I am not able to run anything. For example when I try to run the test cases I'm getting deprecation warning and an error (see the output below).

Does somebody have an idea?

python manage.py test
api
api.urls
/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/jsonview/decorators.py:10: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  from django.utils.importlib import import_module

/Users/nutrina/temp/appointment/appointment/appointment/api/models.py:7: RemovedInDjango19Warning: Model class api.models.UserProfile doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class UserProfile(models.Model):

/Users/nutrina/temp/appointment/appointment/appointment/api/models.py:11: RemovedInDjango19Warning: Model class api.models.Office doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class Office(models.Model):

/Users/nutrina/temp/appointment/appointment/appointment/api/models.py:43: RemovedInDjango19Warning: Model class api.models.OfficeSchedule doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class OfficeSchedule(models.Model):

Creating test database for alias 'default'...
Got an error creating the test database: database "test_appointment" already exists

Type 'yes' if you would like to try deleting the test database 'test_appointment', or 'no' to cancel: yes
Destroying old test database 'default'...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
    old_config = self.setup_databases()
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
    **kwargs
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 368, in create_test_db
    test_flush=True,
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
    cursor.execute(statement)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/nutrina/.virtualenvs/appointment_2/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_group" does not exist
Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52
nutrina
  • 1,002
  • 1
  • 12
  • 26

1 Answers1

2

Depending on the version of Django I would suggest doing a syncdb and a fake migrations if it is 1.7 or less.

python manage.py syncdb --all
python manage.py migrate --fake

If it is greater than 1.7 make sure that you have created a migration whenever you add or change a model and then apply it.

python manage.py makemigrations app_name
python manage.py migrate app_name

For more information please refer to https://docs.djangoproject.com/en/1.8/topics/migrations/

Another option is that some of the packages that you used on your first virtualenv is different from your second. If you still have the original working version I would suggest doing a pip freeze and then installing the requirements on the new virtualenv.

On working virtualenv (make sure you are in the project directory)

pip freeze > requirements.txt

On new virtualenv

pip install -r requirements.txt

Hope this helps!

Justin Ober
  • 839
  • 6
  • 14
  • running makemigrations and migrate solved my problem partially, meaning I can run the server and I can also run the tests. But what remains are the warnings: /Users/nutrina/Projects/personal/appointment/appointment/appointment/api/models.py:7: RemovedInDjango19Warning: Model class api.models.UserProfile doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. – nutrina Apr 16 '15 at 14:49
  • First I am glad that you were able to get the server running. Secondly this is an unrelated topic so I will point you to http://stackoverflow.com/questions/29635765/django-1-9-deprecation-warnings-app-label I am trying to figure this one out right now and I will post it to the question linked. Thanks :) – Justin Ober Apr 16 '15 at 16:47
  • Thanks, that solution in the question linked worked. Although, I cannot understand the necessity of declaring an app_label, since the models.py file is part of an application anyway ... – nutrina Apr 16 '15 at 19:43
  • 1
    I added an edit to the question but in short django doesn't know that the model is apart of a specific app so it needs to be set explicitly. Although it sounds like in your case it is within the app directory and in a models.py file. In which case I do not have enough information to debug this any further. – Justin Ober Apr 16 '15 at 20:10