Django project #2: SQLite setup



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/11/django-project-2-sqlite-setup/

You should be redirected in 2 seconds.



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.

  1. Install SQLite 3
    sofeng@tortoise:~$ sudo apt-get install sqlite3
  2. Edit settings.py
    cd to the mysite directory created last time.
    sofeng@tortoise:~$ cd ~/Web/mysite
    Edit settings.py and change the following 2 lines
    DATABASE_ENGINE = 'sqlite3'
    DATABASE_NAME = '/home/sofeng/Web/mysite/mydb'
  3. 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: youremail@yourhost.com
    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.
  4. 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.

No comments:

About

This is my *OLD* blog. I've copied all of my posts and comments over to my NEW blog at:

http://www.saltycrane.com/blog/.

Please go there for my updated posts. I will leave this blog up for a short time, but eventually plan to delete it. Thanks for reading.