在我的应用程序,我编辑这里显示迁移文件:schema.rb文件没有更新
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
有生物和署名领域。但是,当我运行rake db:reset时,schema.rb文件中没有更改。我看到的唯一错误,有这个代码块:
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 db:reset时,第一行的rescue语句显示:Warning:not procesing table schema_migrations。编号缺失?
我想我很困惑,为什么这句话能拯救这个?尽管看起来可能是原因,但是在访问seeds.rb文件之前是否发生了schema.rb重置?
这里是耙分贝的输出:迁移:状态
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
我没有尝试过,是否有可能需要运行rake db:rollback多次? –
我在rake db:migrate:status的输出中编辑了我的原始问题 –
有关如何回滚特定迁移的信息,请参阅http://stackoverflow.com/a/6635407/429758。 –