【发布时间】:2015-07-02 11:45:30
【问题描述】:
在我的应用中,我编辑了此处显示的迁移文件:
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 和 byline 字段。但是,当我运行 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 时,第一行中的救援语句显示:警告:未处理表 schema_migrations。身份证不见了?
我想我很困惑为什么这个声明正在拯救这个?虽然看起来可能是原因,但是schema.rb重置不是在访问seeds.rb文件之前发生的吗?
这是 rake db:migrate:status 的输出
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
【问题讨论】:
标签: ruby-on-rails postgresql rake