简体   繁体   English

为什么迁移不起作用

[英]Why migration doesn't work

I have a migration AddAuthenticableToUser.我有一个迁移 AddAuthenticableToUser。 (rake db:migrate:up VERSION=..) works fine, but when I'm trying to rollback a migration (rake db:migrate:down VERSION=..) it doesn't works. (rake db:migrate:up VERSION=..) 工作正常,但是当我尝试回滚迁移时 (rake db:migrate:down VERSION=..) 它不起作用。 Any errors or warnings.任何错误或警告。 Could you help me with this?你能帮我解决这个问题吗?

def self.up
  change_table :users do |t|
    t.token_authenticatable
  end
  add_index :users, :authentication_token, :unique => true
end

def self.down
  remove_index :users, :authentication_token                                                                                                                      
  remove_column :users, :authentication_token
end                                                                                                                                                                                                                                                                                                                                         

This should be the trick.这应该是诀窍。 I think you named your table token_authenticatable and then tried to remove authentication_token.我认为您将表命名为 token_authenticable,然后尝试删除 authentication_token。

def self.up
  create_table :reviews do |t|
    t.column :authentication_token
  end
  add_index :users, :authentication_token, :unique => true
end

def self.down
  remove_index :users, :authentication_token                                                                                                                      
  remove_column :users, :authentication_token
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM