我最近从django项目根文件夹中删除了venv
,以便在根文件夹之外重新创建它。
从那时起,我在运行python manage.py
命令时观察到一些不一致之处,我认为这可能与此venv
“重置”有关。
例如,我没有运行任何问题:
python manage.py runserver
python manage.py makemigrations my_app
但是当我运行例如
python manage.py migrate my_app --database my_db
我得到:
Migrations for 'my_app':
my_app/migrations/0007_auto_20190329_1417.py
- Alter field description on subtask
(my-venv) [myname@myname-VirtualBox myproject](develop)$ python manage.py migrate my_app --database my_db
/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Operations to perform:
Apply all migrations: my_app
Running migrations:
Applying my_app.0007_auto_20190329_1417... OK
Traceback (most recent call last):
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column django_content_type.name does not exist
LINE 1: SELECT "django_content_type"."id", "django_content_type"."na...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 226, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/sql.py", line 51, in emit_post_migrate_signal
**kwargs
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/contrib/auth/management/__init__.py", line 59, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/contrib/contenttypes/models.py", line 51, in get_for_model
ct = self.get(app_label=opts.app_label, model=opts.model_name)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/models/query.py", line 393, in get
num = len(clone)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/models/query.py", line 250, in __len__
self._fetch_all()
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
cursor.execute(sql, params)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column django_content_type.name does not exist
LINE 1: SELECT "django_content_type"."id", "django_content_type"."na...
或者例如
python manage.py showmigrations
我明白了
/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Traceback (most recent call last):
File "manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/commands/showmigrations.py", line 45, in handle
return self.show_list(connection, options['app_label'])
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/core/management/commands/showmigrations.py", line 61, in show_list
loader = MigrationLoader(connection, ignore_no_migrations=True)
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
if self.has_table():
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/home/myname/dj-workspace/my-venv/lib/python3.6/site-packages/django/db/backends/dummy/base.py", line 20, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
我不确定为什么会出现这些错误,尤其是settings.DATABASES is improperly configured. Please supply the ENGINE value.
,因为使用runserver
,该项目能够毫无问题地访问settings.py
中定义的数据库。
我尝试遵循解决方案here,但是即使showmigrations
无法正常工作也无法解决,并且希望避免在可能的情况下重置所有迁移文件。
有人知道什么可能导致这些不一致吗?