futabooo blog

色々手をつけすぎてすぐに忘れるので備忘録

Djangoドキュメントのチュートリアルやってみる

Djangoドキュメントのチュートリアル(http://djangoproject.jp/doc/ja/1.0/intro/tutorial01.html

settings.pyを書き換える所でちょっとつまったのでメモ。

DATABASES = {
    'default': {
        'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
	'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

エラーの内容
django.core.exceptions.ImproperlyConfigured: 'sqlite3' isn't an available database backend.
Try using django.db.backends.sqlite3 instead.
Error was: No module named base


コメントにAddってあるのだからデフォルトの状態に付け加えるのがただしかった。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
	'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}


今度はこんなエラー。セッティングで名前がないってことか。
django.core.exceptions.ImproperlyConfigured: Please fill out the database NAME in the settings module before using the database.


sqlite3を使う場合はデータベースファイルのフルパス。
ここで???データベースファイルってなんぞ?しかし、sqliteを使う場合はとりあえずファイルのパスを指定すれば、
ファイルがない場合、自動でファイル作成もしてくれるらしい。
ということでファイルおいてほしいところのパスを書いてもっかい。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
		'NAME': '/Users/futabooo/mysite_django.db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}
$ python manage.py syncdb

でけた。


つくったデータベースに接続

sqlite3 mysite_django.db


つくられたテーブルがどんなんかを表示させる

sqlite> .schema


ひとまずここまできた。