简体   繁体   中英

python sqlite3 BASE_DIR is not recognized as the name

I use Windows 10 and I just start 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. 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?

(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使默认的 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. 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?

(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. 'NAME': BASE_DIR / 'db.sqlite3' is in DATABASES dictionary which contains all databases in your Django project. The first item is 'default' (the default database). 'NAME' means the path to the database file. In your project the path is 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. At the top of settings.py BASE_DIR is defined as BASE_DIR = Path( file ).resolve().parent.parent So it is a Path object. 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. The result is a Path object. For Path objects there is / operator which can be used to append relative path of a folder or a file to the object path. Here BASE_DIR / 'db.sqlite3' means add filename db.sqlite3 to BASE_DIR path. In simple words BASE_DIR / 'db.sqlite3' means db.sqlite file which located two folders up from current file ( settings.py ). You can achieve appending db.sqlite to BASE_DIR by using join module-level function of os.path module. You are not supposed to use / operators of Path objects exclusively. 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. 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. For installing SQLite v3 go to https://www.sqlite.org/download.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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