Ruby Sequel error, table already exists

I realized that I can't run the tutorial (http://sequel.jeremyevans.net/) twice.

The first time, it runs as we expect. But the second time, it raises an error

SQLite3::SQLException: table `items` already exists (Sequel::DatabaseError)

I understand the error, but I don't know how to fix it.

How can I open the DB without losing the data it contains, and still being able to run the tutorial?


The problem is, it tries to create a DB with the same name, but it already exists, so it raises an error.

Solution:

  • create_table Try to create the table, raise an error if already exists.
  • create_table! Drop the table if exists, and then create the table (YOU LOSE YOUR DATA).
  • create_table? Create the table only if it doesn't exist.