Wednesday, March 11, 2015

Sqlite3

Sqlite3 is a light-weighted database server. It comes directly with Django.

Here is an introduction to its use: http://www.sqlite.org/sessions/sqlite.html

Some common commands:

- to enter sqlite3 shell: sqlite3 [sqlite3 db filename]
- show all databases: .databases
- show all tables: .tables
- query a table: select * from sqlite_master;
- show all table schema: .schema
- backup database to another file: .backup another_db.db
- exit shell: .q, or .exit

Note that there is only 1 database per database file in Sqlite3. So there is no command like "use database1".

Some notes:

- For sqlite3 database to be writable, it should be writable by the web account, its containing folder should also be writable by the web account.

- If a column in missing in a table, you can do this to add it:
sqlite3 yourdb.db
> drop table bookmarks_bookmark;
> .quit
cd yourpythonproj
python manage.py syncdb
python manage.py runserver

Basically, syncdb cannot change integrate schema once the tables are created. You have to drop that table first (or maybe need to remove the database totally, which can be done by mv the current db.sqlite3 to db.sqlite3.bak and do syncdb).




No comments:

Blog Archive

Followers