Solve the problem of opening Django's built-in database Sqlite in the pycharm environment

Problem Description

After writing a record in the database file, an error occurs when executing the command to view the table in the terminal of pycharm.

The execution statement is:

Error when connecting to database

python manage.py dbshell

CommandError: You appear not to have the 'sqlite3' program installed or on your path.

Error: unable to open database "E:\xx\db.sqlite3": unable to open database file
CommandError: "sqlite3 E:\xx\db.sqlite3" returned non-zero exit status 1.

Solution

1) Place the executable file of sqlite3 in the C:\Windows\System32 directory

Executing again still reports an error

However, you can successfully access the database command line terminal by executing the following command:

sqlite3

 But still can't open the database file

The problem is: the version of sqlite3 is too low. Carefully observe the version output by the terminal: 3.7.14 updated version in 2012.

2) Update sqlite3 to the latest version

https://www.sqlite.org/download.html 

 

 Just select sqlite3.exe.

After placing sqlite3 in the specified directory, return to the pycharm terminal and execute the sqlite3 command:

3) Execute the following command to successfully view the database table file

.open db.sqlite3
select * from authorization_user;

Table records successfully accessed.

Other operations that can be performed to view database tables are:

1. Double-click the database file db.sqlite3 in pycharm

Open the consoledb client and enter the sql operation statement.

select * from authorization_user;

 2. Change the operation in the pycharm command line to execute in the anaconda powershell prompt

Other commands

Database file migration under the Django framework, operations performed after changing the data model file:

Check whether the data model has changed, and if so, generate a file to record the changes  

python manage.py makemigrations

 Data change migration modification 

python manage.py migrate

 

reference

[1] Django study notes of python (1)---Building a Django development environment and some basic commands

【2】python - sqlite3.OperationalError: unable to open database file - Stack Overflow

【3】 https://www.sqlite.org/download.html 

Guess you like

Origin blog.csdn.net/heda3/article/details/130907772