Sunday, May 9, 2010

Updating sqlite database from the command line - django

I'm working with django today and realized halfway through that my database was incorrect. I needed to drop columns from a table and create a new table. The syncdb command, from what I've read, does create new tables, but it will not drop columns. So, I had to directly access the sqlite database from the command line. Luckily this is pretty easy. Just navigate in the Terminal window to the directory where the database file is saved. Then run the following command:

sqlite3 [database filename]

This will start sql in the Terminal window. From here, you can run the typical sql commands to select rows, update rows, etc. In my case, I simply dropped all tables so I could start from scratch:

DROP TABLE search_searchresult;

This could be a very useful for other problems, such as uploading bulk data.

No comments:

Post a Comment