Django project #2: SQLite setup
In the first installment of the Sample Django Project, I installed Django and created a project. In this installment, I will set up the SQLite database. At first, I thought I had to figure out what kind of data to put in the database, but in actuality, I can create an empty database and fill it in later. That is what I am doing. Here are the steps.
- Install SQLite 3
sofeng@tortoise:~$ sudo apt-get install sqlite3
- Edit settings.py
cd to the mysite directory created last time.sofeng@tortoise:~$ cd ~/Web/mysite
Editsettings.py
and change the following 2 linesDATABASE_ENGINE = 'sqlite3' DATABASE_NAME = '/home/sofeng/Web/mysite/mydb'
- Create Django tables in the database
sofeng@tortoise:~/Web/mysite$ python manage.py syncdb Creating table auth_message Creating table auth_group Creating table auth_user Creating table auth_permission Creating table django_content_type Creating table django_session Creating table django_site You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'sofeng'): E-mail address: [email protected] Password: Password (again): Superuser created successfully. Installing index for auth.Message model Installing index for auth.Permission model Loading 'initial_data' fixtures... No fixtures found.
- Take a look at the databases created
sofeng@tortoise:~/Web/mysite$ sqlite3 mydb SQLite version 3.4.2 Enter ".help" for instructions sqlite> .schema
You should see a bunch of CREATE TABLE statements. If you get the following error message, it probably means you used sqlite instead of sqlite3.Unable to open database "mydb": file is encrypted or is not a database
Well that was pretty easy. Next time, we'll create some models and actually write some python code.
Comments
for DATABASE_ENGINE, the latest Django installations expect "django.db.backends.sqlite3"