Django警告和错误

时间:2015-04-16 04:31:52

标签: django virtualenv

我正在开展一个小型宠物项目。在我将所有工作都提交到git存储库并将其克隆到新位置之前,一切似乎都很好。

我已经设置了一个新的虚拟环境,其中包含我正在使用的所有模块,这让我感到惊讶:我无法运行任何东西。例如,当我尝试运行测试用例时,我收到了弃用警告和错误(请参阅下面的输出)。

有人有想法吗?

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

1 个答案:

答案 0 :(得分:2)

根据Django的版本,如果它是1.7或更低,我建议你做一个syncdb和假迁移。

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

如果大于1.7,请确保在添加或更改模型时创建了迁移,然后应用它。

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

有关详细信息,请参阅https://docs.djangoproject.com/en/1.8/topics/migrations/

另一个选择是你在第一个virtualenv上使用的一些软件包与你的第二个不同。如果你仍然有原始工作版本,我建议你做一个pip冻结,然后在新的virtualenv上安装这些要求。

关于工作virtualenv(确保你在项目目录中)

pip freeze > requirements.txt

关于新的virtualenv

pip install -r requirements.txt

希望这有帮助!