title: Rails: Getting "Table events has no column named user_id" error on all tests
body: <p>All my tests are giving errors. I tried to sort for a good while, to no avail. They are similar to the following:</p>
  
  <pre><code>30) Error:                                                                                                     
  UserTest#test_a_user_should_enter_a_first_name:                                                                 
  ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
  ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
  7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)                                                  
  
  
   31) Error:                                                                                                     
  UserTest#test_a_user_should_enter_a_last_name:                                                                  
  ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
  ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
  7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)                                                  
  
  
   32) Error:                                                                                                     
  UserTest#test_a_user_should_have_a_profile_name_without_spaces:                                                 
  ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
  ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
  7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962) 
  </code></pre>
  
  <p>I should mention that the app itself is working perfectly fine. Various things depend on the user_id attribute, and they run.</p>
  
  <p>As for tests, I looked around and found a mention of <code>Check your fixtures file! Whenever I'd rename columns, I'd usually forget to tweak my fixtures to match. This causes an error on every single test, just like you're seeing.</code> <a href="https://stackoverflow.com/questions/11065752/error-in-all-unit-and-functional-tests-after-altering-column-names-of-a-table">Error in all unit and functional tests after altering column names of a table</a> Not sure if that applies to my issue though. As you can see, it says events already has a user_id. I don't quite get how all the tests are failing, even seemingly unrelated ones. That's what's throwing me off.</p>
  
  <p>My section of GitHub: <a href="https://github.com/attatae/and_silva" rel="nofollow noreferrer">https://github.com/attatae/and_silva</a></p>
  
  <p>Also looked at this: <a href="https://stackoverflow.com/questions/6161988/rails-3-0-7-with-ruby-1-9-2-fixtures-with-belongs-to-and-has-many-gives-table">Rails 3.0.7 with ruby 1.9.2 fixtures with :belongs_to and :has_many gives &quot;table users has no column named posts&quot;</a></p>
  
  <p>Do I need to insert user_id into xxyynum_create_events.rb?
  <code>ie integer :user_id</code> under <code>create table :events do |t|</code></p>
  
  <p>Other things I tried:
  rake db:test:prepare
  rake db:migrate RAILS_ENV=test
  dropping then recreating the db</p>
  
  <p>All help very appreciated.</p>
  
  <p><strong>Update</strong>===============</p>
  
  <p>After posting, I changed my [bignum]_create_events.rb to look like so:</p>
  
  <pre><code>class CreateEvents &lt; ActiveRecord::Migration
    def change
      create_table :events do |t|
        t.string :title
        t.datetime :time_begin 
        t.string :location
        t.date :event_start
        t.text :text
        t.integer :user_id
        t.text :user 
  
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p>I then tried doing <code>bundle exec rake db:reset &amp;&amp; bundle exec rake db:populate &amp;&amp; bundle exec rake db:test:prepare</code> but received an error `"Don't know how to build task 'db:populate'. </p>
  
  <p>So I tried <code>bundle exec rake db:drop &amp;&amp; bundle exec rake db:create &amp;&amp; bundle exec rake db:migrate &amp;&amp; bundle exec db:test:prepare</code> instead, but it said 
  <code>no such table: events: ALTER TABLE "events" ADD "address" varchar(255)C:/Rails Projects/Git pull/and_silva/db/migrate/20140329045140_add_address_to_event.rb:3:in</code>change'`</p>
  
  <p>Next I went into dev and test sandboxes, and they both said that <code>Event(Table doesn't exist)</code>.</p>
  
  <p>Then I tried running rails s just to make sure I was even trying to fix the right program, since my application was running earlier just fine, apparently with no user_id aspect in events. </p>
  
  <p>The site said <code>Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue.</code> I tried running rake db:migrate instead. Then it said:</p>
  
  <pre><code>==  AddAddressToEvent: migrating ==============================================
  -- add_column(:events, :address, :string)
  rake aborted!
  An error has occurred, this and all later migrations canceled:
  
  SQLite3::SQLException: no such table: events: ALTER TABLE "events" ADD "address" varchar(255)C:/Rails Projects/Git pull/and_silva/db/migrate/20140329045140_add_address_to_event.rb:3:in *change'
  C:in `migrate'
  Tasks: TOP =&gt; db:migrate
  </code></pre>
  
  <p>Then I ran rake and got the same exact errors as before for 32 tests. </p>
  
  <p>I ran rake db:migrate RAILS_ENV=development and then got the same AQLite3 [...] ALTER TABLE error.</p>