【问题标题】:Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development迁移待定。要解决此问题,请运行: bin/rake db:migrate RAILS_ENV=development
【发布时间】:2014-08-13 15:27:00
【问题描述】:

This is the error I am getting 当我尝试查看我使用 ruby​​ on rails 创建的页面时。问题是,我已经将我的数据库从 mysql 迁移到了我的 ruby​​ 应用程序。我可以在 schema.rb 文件夹中看到它

ActiveRecord::Schema.define(version: 0) do

  create_table "users", force: true do |t|
    t.string "first_name", null: false 
    t.string "last_name",  null: false
    t.string "username",   null: false
    t.string "password",   null: false
    t.string "email",      null: false
  end

end

这是我的迁移文件夹中的迁移文件

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.timestamps
    end
  end
end

我要做的就是为该数据库运行一个脚手架,但我不断收到错误。

【问题讨论】:

  • 您的表如何在没有迁移的情况下拥有这些列(first_name、last_name 等)?
  • define(version: 0) 表示数据库从未迁移过,当您迁移它时,此数字会更新为迁移时间戳,应该类似于:define(version: 20140810211014)。也许您的迁移由于某种原因没有成功,请尝试再次运行它们并检查是否有任何错误。
  • rake db:migrate --trace 的输出添加到您的问题或要点中。
  • 我摆脱了页面上的错误(通过我在以下答案中采取的行动)它将版本更改为 ActiveRecord::Schema.define(version: 20140813133141) 我猜是一件好事。但是,当我这样做时,它取出了有关数据库的所有信息 (t.string "first_name", null: false t.string "last_name", null: false)

标签: mysql ruby-on-rails ruby rails-activerecord rails-migrations


【解决方案1】:

好的,我想我已经想通了。由于上面的评论,我运行了rake db:migrate --trace,并得到了一个开始时的巨大错误:

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
ActiveRecord::NoDatabaseError: Unknown database 'recipe_library_development'Run `$ bin/rake db:create db:migrate` to create your database

因此,基于此,我运行了:bin/rake db:create db:migrate

我重新加载了我的页面,错误消失了。

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    • 2015-01-27
    • 1970-01-01
    • 2014-02-08
    • 2015-04-01
    • 2014-02-14
    相关资源
    最近更新 更多