Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite 3 Database with Django

I am stuck on Django Documentation tutorial on displaying SQLite table.

" If you’re interested, run the command-line client for your database and type \dt (PostgreSQL), SHOW TABLES; (MySQL), or .schema (SQLite) to display the tables Django created. "

I have created a project named mysite. Location : C:\Python34\Scripts\mysite

Inside mysite, there are mysite folder, db.sqlite3, and manage.py.

I opened command prompt and navigate to C:\Python34\Scripts\mysite and I type .schema and it returns " . schema is not recognized.. "

My settings.py database file :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join('BASE_DIR' , 'db.sqlite3'),
    }
}

I also can't define BASE_DIR. I don't know about the db.sqlite3 file. I cannot know if the file is .db extension.

Could someone help me to find out ?

like image 806
billyhalim25 Avatar asked Aug 01 '15 14:08

billyhalim25


People also ask

Can you use SQLite with Django?

By default, the configuration uses SQLite. If you're new to databases, or you're just interested in trying Django, this is the easiest choice. SQLite is included in Python, so you won't need to install anything else to support your database.

Which DB works best with Django?

Django officially supports the following databases: PostgreSQL. MariaDB. MySQL.

What is SQLite database in Django?

sqlite3'. The file is database file where all the data that you will be generating will be stored. It is a local file as Django is a server-side framework and it treats your computer as the host when you actually run the server in command line/terminal.


2 Answers

.schema is a command you would run inside of the sqlite3 command line interface to get a list of tables in that database.

If you don't already have it installed, you can download sqlite3 command line interface here and install it: https://www.sqlite.org/download.html

Once you have sqlite3 installed, you can:

  • Change directories to the folder containing your sqlite3 database file

    cd C:\Python34\Scripts\mysite

  • Open the database file with the sqlite3 command line interface

    sqlite3 db.sqlite3

  • Get a list of tables by typing .schema at the sqlite3 command line interface prompt

    .schema

like image 102
Joe Young Avatar answered Sep 28 '22 16:09

Joe Young


You didn't "run the command-line client for your database", you simply navigated to the directory. The command-line client is "sqlite3", although you may not have it installed on Windows.

You don't need to define BASE_DIR, it is already defined higher up in the settings file, but you do need to refer to it as a variable, not a string:

'NAME': os.path.join(BASE_DIR , 'db.sqlite3'),
like image 41
Daniel Roseman Avatar answered Sep 28 '22 15:09

Daniel Roseman