6

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 ?

billyhalim25
  • 323
  • 1
  • 2
  • 16

5 Answers5

9

.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

Joe Young
  • 5,749
  • 3
  • 28
  • 27
  • The Django Documentation states : "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". Is it mean I don't have to install SQLite again ? – billyhalim25 Aug 01 '15 at 14:34
  • Then you should be able to type "sqlite3 -version" in your windows console and get a response. If so, you don't need to install the sqlite3 command line interface. You can just proceed with the rest of the steps. – Joe Young Aug 01 '15 at 14:38
  • It appears "sqlite3 is not recognized...". So, I have to install again, right? – billyhalim25 Aug 01 '15 at 14:40
  • 2
    I think what django installed for you was just the sqlite3 database driver. So technically, you don't need the sqlite3 command line interface to run a Django project with sqlite3 support. You only need the sqlite3 command line interface if you want to take a look around in the database outside of Django. So yes, if you want to see whats in there using the ".schema" command, you'll need to install the sqlite3 command line interface. :) – Joe Young Aug 01 '15 at 14:44
  • Okay, I will install it. Thank you for your explanation. – billyhalim25 Aug 01 '15 at 14:54
5

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'),
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
2

BASE_DIR is not a string. It is a variable whose value is automatically declared by django in settings.py file. You just need to remove the quotes in your usage of BASE_DIR.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR , 'db.sqlite3'),
    }
}
Animesh Sharma
  • 3,258
  • 1
  • 17
  • 33
1

You may have to change in settings.py file for Database. Place 'NAME':'db.sqllite3', in Database dict.

This will create db.sqlite3 file in your project dir. It has resolved my issue. Hope this helps.

Jyoti
  • 27
  • 2
0

BASE_DIR is variable and not string, add import os and BASE_DIR case you need

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR , 'db.sqlite3'),
    }
}
Willem
  • 1,304
  • 1
  • 8
  • 7