【问题标题】:rake db:migrate does not change tablerake db:migrate 不改变表
【发布时间】:2013-11-17 00:19:45
【问题描述】:

我有一个带有列(名称、路径)的数据库。现在我有一个迁移文件,将列更改为(名称、pathorig、pathjson、scramble)。

执行rake db:resetrake db:migrate 不会更新表格。为什么会发生这种情况?

我的迁移文件:

class CreateUploads < ActiveRecord::Migration
  def change
    create_table :uploads do |t|
      t.string :name
      t.string :pathorig
      t.string :pathjson
      t.string :scramble

      t.timestamps
    end
  end
end

schema.rb 文件:

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

  create_table "uploads", force: true do |t|
    t.string   "name"
    t.string   "path"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end

【问题讨论】:

    标签: ruby-on-rails ruby rake dbmigrate


    【解决方案1】:

    Difference between rake db:migrate db:reset and db:schema:load 很好地解释了各种rake db:* 命令的作用。

    因为rake db:reset 执行db:schema:load,它会从您的表中加载旧列,而不是调用db:migrate,这就是您的迁移未运行的原因。

    考虑编写一个更改这些列名称的迁移,而不是重新创建现有表,或者手动运行rake db:drop; rake db:create db:migrate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-28
      • 2014-06-20
      • 2018-10-06
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 2020-01-26
      相关资源
      最近更新 更多