2016-07-15 128 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 –