在我的应用程序中,我编辑了一个迁移文件,如下所示:
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文件中没有任何更改。我在以下代码块中看到的唯一错误是:
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的输出:迁移:状态
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发布于 2015-04-24 03:25:09
要在迁移文件中应用新的更改,需要运行rake db:migrate。如果在进行更改之前已经运行了迁移,那么运行rake db:rollback以回滚迁移并再次应用它。
rake db:reset不会在迁移文件中应用新的更改。它试图加载schema.rb文件中已经存在的内容。
有关migrations.html#setup-the-database和migrations.html#resetting-the-database如何工作的详细信息,请参阅rake db:reset和migrations.html#resetting-the-database。
运行rake db:migrate:status以查看运行什么迁移。
https://stackoverflow.com/questions/29837867
复制相似问题