简体   繁体   English

python sqlite3 BASE_DIR 不被识别为名称

[英]python sqlite3 BASE_DIR is not recognized as the name

I use Windows 10 and I just start python我使用 Windows 10,我刚启动 python使默认的 sqlite3

  1. why my root code is just 'NAME': BASE_DIR / 'db.sqlite3' , When searching, many people come up with 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') , this way.为什么我的根代码只是'NAME': BASE_DIR / 'db.sqlite3' ,在搜索时,很多人想出了'NAME': os.path.join(BASE_DIR, 'db.sqlite3') ,这样。 Why am I only different?为什么只有我不同?

  2. When I try to check the database, it cannot be checked.当我尝试检查数据库时,无法检查它。 However, it is possible to update the database through migration.但是,可以通过迁移来更新数据库。 How can I check the make sqlite3 of data?如何检查数据的make sqlite3?

(fcdjango_env) PS C:\python_mvt\fc_community> sqlite3 db.sqlite3

sqlite3: The term 'sqlite3' 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.

I use Windows 10 and I just start python我使用 Windows 10,我刚启动 python使默认的 sqlite3

  1. why my root code is just 'NAME': BASE_DIR / 'db.sqlite3' , When searching, many people come up with 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') , this way.为什么我的根代码只是'NAME': BASE_DIR / 'db.sqlite3' ,搜索时,很多人想出'NAME': os.path.join(BASE_DIR, 'db.sqlite3') ,这样。 Why am I only different?为什么只有我不同?

  2. When I try to check the database, it cannot be checked.当我尝试检查数据库时,无法检查它。 However, it is possible to update the database through migration.但是,可以通过迁移来更新数据库。 How can I check the make sqlite3 of data?如何检查数据的make sqlite3?

(fcdjango_env) PS C:\python_mvt\fc_community> sqlite3 db.sqlite3

sqlite3: The term 'sqlite3' 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.

You asked two questions:你问了两个问题:

  1. You were seeing settings.py file in your project folder.您在项目文件夹中看到settings.py文件。 'NAME': BASE_DIR / 'db.sqlite3' is in DATABASES dictionary which contains all databases in your Django project. 'NAME': BASE_DIR / 'db.sqlite3'位于 DATABASES 字典中,该字典包含 Django 项目中的所有数据库。 The first item is 'default' (the default database).第一项是“默认” (默认数据库)。 'NAME' means the path to the database file. 'NAME'表示数据库文件的路径。 In your project the path is BASE_DIR / 'db.sqlite3' .在您的项目中,路径是BASE_DIR / 'db.sqlite3' Look at the name BASE_DIR , it is the naming convention of constants in python (and many other languages), words in capital letters separated with underscore.看名字BASE_DIR ,它是python(和许多其他语言)中常量的命名约定,大写字母的单词用下划线分隔。 At the top of settings.py BASE_DIR is defined as BASE_DIR = Path( file ).resolve().parent.parent So it is a Path object.settings.py的顶部BASE_DIR被定义为BASE_DIR = Path( file ).resolve().parent.parent所以它是一个Path对象。 It is instantiated by passing file special variable (which contains absolute path of current module here settings.py ) to constructor of Path class, then resolving it (ie turning any symlinks and environment variables to their actual values), and at the last get the folder that is two levels up in the filesystem hierarchy by using parent twice.它通过将文件特殊变量(此处包含当前模块的绝对路径settings.py )传递给 Path 类的构造函数来实例化,然后解析它(即将任何符号链接和环境变量转换为它们的实际值),最后得到通过使用 parent 两次,在文件系统层次结构中向上两级的文件夹。 The result is a Path object.结果是一个 Path 对象。 For Path objects there is / operator which can be used to append relative path of a folder or a file to the object path.对于 Path 对象,有 / 运算符可用于将文件夹或文件的相对路径附加到对象路径。 Here BASE_DIR / 'db.sqlite3' means add filename db.sqlite3 to BASE_DIR path.这里BASE_DIR / 'db.sqlite3'表示将文件名db.sqlite3添加到BASE_DIR路径。 In simple words BASE_DIR / 'db.sqlite3' means db.sqlite file which located two folders up from current file ( settings.py ).简单来说BASE_DIR / 'db.sqlite3'表示db.sqlite文件,它位于当前文件( settings.py )的两个文件夹之上 You can achieve appending db.sqlite to BASE_DIR by using join module-level function of os.path module.您可以通过使用os.path模块的join模块级函数来实现将db.sqlite附加到BASE_DIR You are not supposed to use / operators of Path objects exclusively.您不应该专门使用 Path 对象的 / 运算符。 The result is the same.结果是一样的。
  2. You typed the command of sqlite3 db.sqlite3 and here you passed db.sqlite3 argument to sqlite3.exe which must be either in the current directory of path of it must exists in PATH system environment variable.您输入了sqlite3 db.sqlite3的命令,在这里您将db.sqlite3参数传递给sqlite3.exe ,它必须位于其路径的当前目录中,并且必须存在于 PATH 系统环境变量中。 Hence the error means you either have not installed SQLite v3 on your system or have not added its path to PATH system environment variable.因此,该错误意味着您要么没有在系统上安装 SQLite v3,要么没有将其路径添加到 PATH 系统环境变量中。 For installing SQLite v3 go to https://www.sqlite.org/download.html .要安装 SQLite v3,请访问https://www.sqlite.org/download.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM