Django 警告和错误
Django Warnings and Errors
我正在做一个小宠物项目。在我将所有工作提交到 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
根据 Django 的版本,如果是 1.7 或更低版本,我建议执行同步数据库和假迁移。
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 freeze,然后在新的 virtualenv 上安装要求。
正在运行 virtualenv(确保您在项目目录中)
pip freeze > requirements.txt
在新的 virtualenv 上
pip install -r requirements.txt
希望对您有所帮助!
我正在做一个小宠物项目。在我将所有工作提交到 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
根据 Django 的版本,如果是 1.7 或更低版本,我建议执行同步数据库和假迁移。
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 freeze,然后在新的 virtualenv 上安装要求。
正在运行 virtualenv(确保您在项目目录中)
pip freeze > requirements.txt
在新的 virtualenv 上
pip install -r requirements.txt
希望对您有所帮助!