title: Foreign Key constraint issues using sequel and database cleaner
body: <p>I am running into issues using <a href="https://github.com/DatabaseCleaner/database_cleaner" rel="noreferrer">database cleaner</a> with <a href="https://github.com/jeremyevans/sequel" rel="noreferrer">sequel</a> and sqlite foreign key constraints. Specifically, I am using the <code>:truncation</code> strategy with Capybara integration tests.</p>
  
  <p>For the given sample schema:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT);
  CREATE TABLE events(id INTEGER PRIMARY KEY, title TEXT);
  
  CREATE TABLE events_users(
    user_id INTEGER,
    event_id INTEGER,
  
    FOREIGN KEY(user_id) REFERENCES users(id),
    FOREIGN KEY(event_id) REFERENCES events(id)
  );
  </code></pre>
  
  <p>And sequel models:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>class User &lt; Sequel::Model
    many_to_many :events
  end
  
  class Event &lt; Sequel::Model
    many_to_many :users
  end
  </code></pre>
  
  <p>Running the following:</p>
  
  <pre><code># normally this would be run in
  # an rspec before(:each) for my :feature specs
  DatabaseCleaner.start
  DatabaseCleaner.strategy = :truncation
  
  bob = User.create(name: "bob")
  sally = User.create(name: "sally")
  event = Event.create(title: "Everyone's invited")
  event.users &lt;&lt; [bob, sally]
  
  DatabaseCleaner.clean
  </code></pre>
  
  <p>Results in an error</p>
  
  <pre><code>SQLite3::ConstraintException: FOREIGN KEY constraint failed (Sequel::ForeignKeyConstraintViolation)
  </code></pre>
  
  <p>I can get around this by altering my before statement to disable the foreign_keys PRAGMA:</p>
  
  <pre><code>DB.foreign_keys = false
  DatabaseCleaner.start
  DatabaseCleaner.strategy = :truncation
  </code></pre>
  
  <p>(or not using FOREIGN KEY in my tables), but that seems wrong since I want the benefits that foreign keys constraints — or at least I think I do ;).</p>
  
  <p>Is this a fundamental misunderstanding of how to use foreign key constraints, or is there a better way to do this?</p>