2015-10-15 41 views
1

我對Rails世界還很新。我一直在研究一項技能,所以我認爲我會給Omni-Auth twitter一個破解。我已經通過本教程閱讀SitePoint:遷移時出錯:SQLite3 :: SQLException:沒有這樣的表:main.users

Rails Authentication with OAuth 2.0 and OmniAuth

我發現,直到那裏有我跑rake db:migrate之前創建一個用戶模型和修改遷移文件的位置。下面是根據這些指示我的移民文件:

class CreateUsers < ActiveRecord::Migration 
    def change 
    create_table :users do |t| 
     t.string :provider, null: false 
     t.string :uid, null: false 
     t.string :name 
     t.string :location 
     t.string :image_url 
     t.string :url 
     add_index :users, :providers 
     add_index :users, :uid 
     add_index :users, [:provider, :uid], unique: true 

     t.timestamps null: false 
    end 
    end 
end 

但是當我運行rake db:migrate它拋出這個錯誤:

SQLite3::SQLException: no such table: main.users: CREATE INDEX "index_users_on_providers" ON "users" ("providers")/Users/jrshafer/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize' 

你能提供這個抱負的開發商任何幫助將非常感激。

您可以查看完整的回購在這裏: kronoTweeter GitHub Repo

回答

2

你應該在一個塊創建表,然後添加索引。但是,在您當前的代碼中,您正試圖在同一塊create_table塊中添加索引。

嘗試用這段代碼替換當前代碼:

class CreateUsers < ActiveRecord::Migration 
    def change 
    create_table :users do |t| 
     t.string :provider, null: false 
     t.string :uid, null: false 
     t.string :name 
     t.string :location 
     t.string :image_url 
     t.string :url 
     t.timestamps null: false 
    end # you have to end the create_table block here 

    # then you have to have the add_index statements 
    add_index :users, :providers 
    add_index :users, :uid 
    add_index :users, [:provider, :uid], unique: true 
    end 
end 

然後運行:

bundle exec rake db:migrate 

這應該可以解決您的問題。

+1

這是答案應該是 –

相關問題