活动管理回滚:“验证失败:电子邮件已被占用”
我正在开始一个带有 postgresql 后端的 Rails 3.1.3 项目。
我生成了一些模型,然后添加了 Active Admin gem。 稍后,我决定应该合并 2 个模型,并希望回滚到开头,以便我可以删除一个模型并使用正确的架构重新启动迁移。
我输入:
rake db:rollback step=10
当它中止回滚时,它很好地达到了 Active Admin 位:
$ rake db:rollback
== DeviseCreateAdminUsers: reverting =========================================
rake aborted!
An error has occurred, this and all later migrations canceled:
Validation failed: Email has already been taken
Tasks: TOP => db:rollback
我没有添加任何用户,所以这可能是 '[电子邮件受保护]' 帐户。
宝石档案
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'pg'
gem 'json'
gem 'activeadmin'
gem 'sass-rails', '~> 3.1.5'
gem 'meta_search', '>= 1.1.0.pre'
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
gem 'mechanize'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'less-rails-bootstrap'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您究竟是如何分两个阶段进行 10 步回滚的?你提出的问题有点不明确,很难给你一个很好的答案。除了向您指出这条信息
http://en.wikibooks.org/ wiki/Ruby_on_Rails/ActiveRecord/Migrations#Managing_Migrations
我建议您检查所有迁移中的声明
。您可能还想使用 Rails 控制台手动删除 AdminUser。
How exactly did you do the 10 step rollback, in 2 stages? The question you pose is a bit underspecified, hard to give you a good answer. Apart from pointing you to this piece of information
http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord/Migrations#Managing_Migrations
I suggest you check all your migrations for a
statement. You may also want to manually remove the AdminUser using the rails console.
在回滚之前运行
rake db:reset
。run
rake db:reset
before the rollback.devise_create_admin_users 迁移在 migrate:up 上创建默认用户,但随后尝试在 rollback/migrate:down 上再次创建它。因此,验证错误,因为电子邮件已经存在。
只需注释掉“AdminUser.create!”在回滚之前,然后在回滚时取消注释。
The devise_create_admin_users migration creates a default user on migrate:up but then tries to create it again on rollback/migrate:down. Hence the validation error, as the email already exists.
Just comment out the 'AdminUser.create!' before rolling back, and then uncomment it when rolling back up.