2016-07-15 129 views
1

當我去我的http://localhost:3000/我得到以下幾點:的Rails:遷移錯誤

ActiveRecord::PendingMigrationError

Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development

提取的源:

# Raises <tt>ActiveRecord::PendingMigrationError</tt> error if any migrations are pending. 
def check_pending!(connection = Base.connection) 
    raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?(connection) 
end 
def load_schema_if_pending! 

此外,當我在控制檯試圖向heroku run rake db:migrate,它說:

StandardError: An error has occurred, this and all later migrations canceled: PG::DuplicateColumn: ERROR: column "email" of relation "users" already exists

我是新來的紅寶石,並按照devise tutorial由Mac肯齊孩子。這是我完成我的第一個Ruby應用程序的最後一步。

我很高興,期待你的幫助! :)

回答

0

你用色器件發電機爲您User模型準備遷移。您的模型已經存在,並已有email列。設計產生的遷移嘗試創建同一列中,果然,失敗了,這是你看到的錯誤的原因:

PG::DuplicateColumn: ERROR: column "email" of relation "users" already exists

爲了解決這個問題只需要打開你的色器件產生的遷移和刪除看起來線像這樣:

t.string :email... 

然後運行rake db:migrate

UPDATE

因爲你的數據庫似乎是與你的遷移同步的,也許應該從頭開始重新創建。

運行

rake db:drop db:create db:migrate 

注意,所有的數據庫中的數據將被破壞。

+0

我試過了,並且在rake db:migrate後仍然出現錯誤,如下所示: rake aborted! StandardError的:發生錯誤,這和所有後來遷移取消: 的SQLite3 ::的SQLException:重複列名:encrypted_pa​​ssword:ALTER TABLE 「用戶」 ADD 「encrypted_pa​​ssword」 VARCHAR DEFAULT '' NOT NULL /用戶/ matthiascordes /。 rvm/gems/ruby​​-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in'initialize' /Users/matthiascordes/.rvm/gems/ruby-2.3.1/gems /sqlite3-1.3.11/lib/sqlite3/database.rb:91:in'new' ...等 –

+0

也是這個,而不是:SQLite3 :: SQLException:沒有這樣的表:users:ALTER TABLE「users」ADD「encrypted_pa​​ssword」varchar DEFAULT''NOT NULL –

+0

請參閱我的答案的更新。 –

1

在控制檯運行rake db:migrate 確保在項目目錄

+0

我可能會添加,運行'heroku run rake db:migrate'在Heroku上運行遷移,而不是在你的localhost上運行。例如關係「用戶」的「PG :: DuplicateColumn:ERROR:列」電子郵件「已經存在的錯誤」通常來自修改遷移名稱或版本。 – Leito

+0

不幸的是,它並沒有幫助。當我這樣做時,我得到: 「rake中止了! StandardError:發生錯誤,此次以及所有後來的遷移取消:」Ater that:「SQLite3 :: SQLException:重複的列名稱:email:ALTER TABLE」users「ADD」電子郵件地址「varchar DEFAULT''NOT NULL」 然後很多關於SQLite3和主動記錄的線條hundrets –