我是rails的新手,我想添加一个字符串迁移文件。不幸的是,我不知道使用迁移是非常危险的。
Adhoc provision profile
我相信我使用了ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
而我使用了rake db:rollback
并且没有任何变化我一直在犯同样的错误
当我尝试rake db:redo
时,这就是我得到的:
rake db:migrate:status
以下是database: /home/ubuntu/workspace/db/development.sqlite3
Status Migration ID Migration Name
--------------------------------------------------
up 20161022035511 Create posts
up 20161022044605 Devise create users
up 20161022045410 Add user id to post
up 20161022050429 Add name to user
up 20161022054826 Add attachment image to posts
up 20161022170851 Create comments
down 20161022184713 Acts as votable migration
down 20161223064636 Add cached votes to posts
的内容:
AddCachedVotesToPosts
这是我在rails c中得到的: 请帮帮我!
答案 0 :(得分:0)
如果这是您的本地数据库而不是生产,那么就解决这个问题。
你可以做到 捆绑exec rake db:drop 捆绑exec rake db:create bundle exec rake db:migrate
[警告]这将删除您存储在本地数据库中的所有内容。
答案 1 :(得分:0)
按如下方式添加两次迁移:
rails g migration RemoveCachedVotesTotalFromPost
:其内容应为:
def change
remove_column :posts, :cached_votes_total
end
rails g migration AddCachedVotesToPost
:其内容应为:
def self.up
add_column :posts, :cached_votes_total, :integer, :default => 0
add_column :posts, :cached_votes_score, :integer, :default => 0
add_column :posts, :cached_votes_up, :integer, :default => 0
add_column :posts, :cached_votes_down, :integer, :default => 0
add_column :posts, :cached_weighted_score, :integer, :default => 0
add_column :posts, :cached_weighted_total, :integer, :default => 0
add_column :posts, :cached_weighted_average, :float, :default => 0.0
add_index :posts, :cached_votes_total
add_index :posts, :cached_votes_score
add_index :posts, :cached_votes_up
add_index :posts, :cached_votes_down
add_index :posts, :cached_weighted_score
add_index :posts, :cached_weighted_total
add_index :posts, :cached_weighted_average
end
def self.down
remove_column :posts, :cached_votes_total
remove_column :posts, :cached_votes_score
remove_column :posts, :cached_votes_up
remove_column :posts, :cached_votes_down
remove_column :posts, :cached_weighted_score
remove_column :posts, :cached_weighted_total
remove_column :posts, :cached_weighted_average
end