我正在学习使用Django,当尝试安装Crispy Forms并运行'makemigrations'时,我遇到了以下错误:
Traceback (most recent call last):
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/models/options.py", line 275, in _get_default_pk_class
pk_class = import_string(pk_class_path)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
return cached_import(module_path, class_name)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import
module = import_module(module_path)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.Falsedb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/javier/Desktop/pd110/src/manage.py", line 22, in <module>
main()
File "/home/javier/Desktop/pd110/src/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/core/management/commands/makemigrations.py", line 156, in handle
loader.check_consistent_history(connection)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/migrations/loader.py", line 313, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 59, in has_table
return self.Migration._meta.db_table in tables
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/utils/functional.py", line 71, in __get__
return self.fget(cls)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 32, in Migration
class Migration(models.Model):
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/models/base.py", line 365, in __new__
new_class._prepare()
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/models/base.py", line 378, in _prepare
opts._prepare(cls)
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/models/options.py", line 329, in _prepare
pk_class = self._get_default_pk_class()
File "/home/javier/Desktop/pd110/lib/python3.10/site-packages/django/db/models/options.py", line 281, in _get_default_pk_class
raise ImproperlyConfigured(msg) from e
django.core.exceptions.ImproperlyConfigured: DEFAULT_AUTO_FIELD refers to the module 'django.Falsedb.models.BigAutoField' that could not be imported.
字符串
我以前执行过迁移,没有任何问题。在我的“settings.py”中,我在“已安装的应用程序”中有以下内容:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'boletin',
]
型
bolster是我的应用程序名称我的项目树结构如下:enter image description here
我尝试在我的虚拟环境中卸载并重新安装Django 4.2.7和Crispy Forms,但它不起作用。如果有人能为我提供一些帮助,我将不胜感激,因为我刚刚开始使用Django,我还没有掌握它。谢谢,对不起我的英语很差
2条答案
按热度按时间8hhllhi21#
我怀疑
django.db.models.BigAutoField
在您的项目中的某个地方错误地变成了django.Falsedb.models.BigAutoField
。查看您的
settings.py
文件,并确保DEFAULT_AUTO_FIELD
选项设置正确,字符串
在
apps.py
文件中也为每个已安装的应用程序设置了相同的设置。型
如果做不到这一点,请在代码库中进行
Falsedb
的全局搜索。bxjv4tth2#
你能提供你试图迁移到数据库的Models.py内容吗?
问题似乎出在“django.Falsedb.models.BigAutoField”语句上。
字符串