首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >schema.rb文件没有更新

schema.rb文件没有更新
EN

Stack Overflow用户
提问于 2015-04-24 02:46:29
回答 1查看 5.1K关注 0票数 2

在我的应用程序中,我编辑了一个迁移文件,如下所示:

代码语言:javascript
复制
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :first_name
      t.string :last_name
      t.string :dj_alias
      t.boolean :site_admin
      t.integer :station_id
      t.string :byline
      t.string :bio

      t.timestamps null: false
    end
  end
end

有bio和署名字段。但是,当我运行rake :reset时,schema.rb文件中没有任何更改。我在以下代码块中看到的唯一错误是:

代码语言:javascript
复制
ActiveRecord::Base.connection.tables.each do |table|
  result = ActiveRecord::Base.connection.execute("SELECT id FROM #{table} ORDER BY id DESC LIMIT 1") rescue ( puts "Warning: not procesing table #{table}. Id is missing?" ; next )
  ai_val = result.any? ? result.first['id'].to_i + 1 : 1
  puts "Resetting auto increment ID for #{table} to #{ai_val}"

  ActiveRecord::Base.connection.execute("ALTER SEQUENCE #{table}_id_seq  RESTART WITH #{ai_val}")
end

在seeds.rb文件的底部,这意味着处理种子文件的索引。当我运行rake :reset时,第一行的救援语句显示:警告: not schema_migrations。身份证不见了?

我想我很困惑为什么这句话能拯救这一切?虽然这看起来可能是原因,但是schema.rb重置不是在访问seeds.rb文件之前发生的吗?

以下是rake db的输出:迁移:状态

代码语言:javascript
复制
 Status   Migration ID    Migration Name
--------------------------------------------------
up     20150225041954  Create songs
up     20150225042739  Create albums
up     20150225043102  Create artists
up     20150225043854  Create playlists
up     20150225044118  Create users
up     20150225044314  Create stations
up     20150225061259  Create featured artists
up     20150225153938  Add devise to users
up     20150225200646  Create reviews
up     20150321171830  Stations users
up     20150323200255  Add last fm to album
up     20150323200432  Add last fm to artist
up     20150323200513  Add last fm to song
up     20150325052314  Albums stations
up     20150325061241  Playlist songs
up     20150327172516  Add image url to albums
up     20150327172532  Add image url to artists
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-24 03:25:09

要在迁移文件中应用新的更改,需要运行rake db:migrate。如果在进行更改之前已经运行了迁移,那么运行rake db:rollback以回滚迁移并再次应用它。

rake db:reset不会在迁移文件中应用新的更改。它试图加载schema.rb文件中已经存在的内容。

有关migrations.html#setup-the-databasemigrations.html#resetting-the-database如何工作的详细信息,请参阅rake db:resetmigrations.html#resetting-the-database

运行rake db:migrate:status以查看运行什么迁移。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29837867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档