4

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?

Quarktum
  • 669
  • 1
  • 8
  • 26
  • In this case you can take a backup of data and drop the table and create again Table and import your backup data – Gagan Gami Sep 04 '14 at 04:41
  • NO! That's terrible! What if you have 10 GB? You can't wait for that twice (when you backup it, and when you import it) – Quarktum Sep 04 '14 at 16:57

1 Answers1

21

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.
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Quarktum
  • 669
  • 1
  • 8
  • 26