活动管理回滚:“验证失败:电子邮件已被占用”

发布于 2024-12-23 05:14:29 字数 1215 浏览 3 评论 0 原文

我正在开始一个带有 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'

I'm at the start of a project in Rails 3.1.3 with a postgresql backend.

I generated a few models and then added the Active Admin gem.
A bit later I decided that I should combine 2 models, and wanted to rollback to the beginning so I could delete one model and restart the migration with the correct schema.

I typed:

rake db:rollback step=10

It went well up to the Active Admin bit, when it aborted the rollback:

$ 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

I have not added any users, so this is probably the '[email protected]' account.

Gemfile

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女情怀诗 2024-12-30 05:14:29

您究竟是如何分两个阶段进行 10 步回滚的?你提出的问题有点不明确,很难给你一个很好的答案。除了向您指出这条信息

http://en.wikibooks.org/ wiki/Ruby_on_Rails/ActiveRecord/Migrations#Managing_Migrations

我建议您检查所有迁移中的声明

AdminUser.create

。您可能还想使用 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

AdminUser.create

statement. You may also want to manually remove the AdminUser using the rails console.

情定在深秋 2024-12-30 05:14:29

在回滚之前运行rake db:reset

run rake db:reset before the rollback.

伴我心暖 2024-12-30 05:14:29

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文