微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – Rails迁移不会改变schema.rb

我有一个rails迁移,不适用于我的schema.rb.迁移应该创建一个表:
class createuserGraphs < ActiveRecord::Migration
  def change
    create_table :user_graphs do |t|
      t.string :name
      t.string :content
      t.integer :user_id
      t.string :type_id
      t.integer :upload_id

      t.timestamps
    end

    add_index :user_graphs,[:user_id,:created_at]
  end
end

我做了db:reset.然后我尝试rake db:migrate:up VERSION = 123123123(这是迁移#).我在我的“开发”环境中.

为什么迁移不影响schema.rb?

解决方法

documentation

rake db:reset任务将丢弃数据库,重新创建它并将当前模式加载到其中.

This is not the same as running all the migrations. It will only use the
contents of the current schema.rb file. If a migration can’t be rolled back,
‘rake db:reset’ may not help you. To find out more about dumping the schema see
‘schema dumping and you.’

所以rake db:reset => db:drop db:create db:schema:load db:seed

要运行所有迁移,请使用:
rake db:drop db:create db:migrate

要么
分贝:迁移:复位=> rake db:drop db:create db:migrate

Reference

原文地址:https://www.jb51.cc/ruby/272230.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐