加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 19:55:07 所属栏目:百科 来源:网络整理
导读:我有一个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
我有一个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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读