我的测试环境:
问题:
我是 Django 新手,目前正在探索它的文档。我按照提供的说明成功完成了第一部分,编写您的第一个 Django 应用程序,第 1 部分(如何设置您的第一个应用程序)。然而,我在理解第二部分编写你的第一个 Django 应用程序,第 2 部分(如何使用数据库)时遇到了困难,特别是在使用数据库方面。
文档提到 SQLite 是默认数据库,无需额外安装即可访问,这与我的理解相符。按照说明,我运行了命令
python manage.py migrate
,没有任何问题。
但是,当尝试使用 SQLite 命令显示创建的表时
.tables
,我遇到了以下错误:
(.venv) PS C:\Users\marco\Desktop\DjangoProject\EuroChampBettingSite> .tables
.tables : The term '.tables' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ .tables
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (.tables:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
此外,尝试使用
sqlite --version
检查 SQLite 版本会产生另一个错误:
(.venv) PS C:\Users\marco\Desktop\DjangoProject\EuroChampBettingSite> sqlite --version
sqlite : The term 'sqlite' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ sqlite --version
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (sqlite:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
问题:
在我的环境中似乎无法识别或正确安装 SQLite,这与文档的建议相反。谁能澄清 SQLite 是否确实包含在 Django 安装中,如果是,我该如何排查和纠正这个问题?任何有关解决此问题的指导将不胜感激。
我在 Windows 上不是 100% 确定,所以我无法帮助您在计算机上安装 SQLite,但是 Django 提供了更好的解决方案。 您可以运行此命令
python manage.py dbshell
并且您已连接到 SQLite 数据库:)