Redmine db:未找到迁移方法

Redmine db:未找到迁移方法

我正在尝试从 redmine 1.0 迁移到 redmine 2.3,但在运行 db:migrate 时出现错误。

sudo rake db:migrate RAILS_ENV=production --trace

(in /opt/redmine-2.3)
/var/lib/gems/1.8/gems/rake-10.0.4/lib/rake/file_utils.rb:9: warning: already initialized constant RUBY
/var/lib/gems/1.8/gems/rake-10.0.4/lib/rake/file_utils.rb:86: warning: already initialized constant LN_SUPPORTED
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
==  BuildProjectsTree: migrating ==============================================
rake aborted!
An error has occurred, all later migrations canceled:

undefined method `inherit_members_changed?' for #<Project:0x7f82e2dad038>
/var/lib/gems/1.8/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:407:in `method_missing'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/attribute_methods.rb:149:in `method_missing'
/opt/redmine-2.3/app/models/project.rb:85:in `_callback_after_748'
/var/lib/gems/1.8/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:460:in `_run__1269722363__save__4__callbacks'
/var/lib/gems/1.8/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `send'
/var/lib/gems/1.8/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/var/lib/gems/1.8/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/var/lib/gems/1.8/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `send'
/var/lib/gems/1.8/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:264:in `create_or_update'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/persistence.rb:104:in `save!'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/validations.rb:56:in `save!'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:in `save!'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in `with_transaction_returning_status'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:in `save!'
/opt/redmine-2.3/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb:185:in `rebuild!'
/opt/redmine-2.3/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb:192:in `call'
/opt/redmine-2.3/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb:192:in `rebuild!'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/relation/delegation.rb:6:in `each'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/relation/delegation.rb:6:in `__send__'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/relation/delegation.rb:6:in `each'
/opt/redmine-2.3/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb:189:in `rebuild!'
/opt/redmine-2.3/app/models/project.rb:416:in `rebuild_tree!'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'
/opt/redmine-2.3/app/models/project.rb:414:in `rebuild_tree!'
/opt/redmine-2.3/db/migrate/105_build_projects_tree.rb:3:in `up'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:370:in `up'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `send'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `migrate'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `__send__'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:777:in `call'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:777:in `ddl_transaction'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `each'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:in `up'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193
/usr/lib/ruby/1.8/rake.rb:636:in `call'
/usr/lib/ruby/1.8/rake.rb:636:in `execute'
/usr/lib/ruby/1.8/rake.rb:631:in `each'
/usr/lib/ruby/1.8/rake.rb:631:in `execute'
/usr/lib/ruby/1.8/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/rake.rb:583:in `invoke'
/usr/lib/ruby/1.8/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2029:in `each'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2023:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2001:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28

问题似乎是 project.inherit_members_changed? 不存在,但在 project.rb 的第 85 行被调用

after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?}

有人知道这个问题的根源是什么吗?

::更新::

我现在尝试升级到 ruby​​ 1.9.3 但出现同样的错误。

rake db:migrate RAILS_ENV=production
==  BuildProjectsTree: migrating ==============================================
rake aborted!
An error has occurred, all later migrations canceled:

undefined method `inherit_members_changed?' for #<Project:0x00000004b36d80>

可能是 Rake 版本的问题吗?

我也运行了 bundle install 并安装了所有需要的 gem。

答案1

您的 Ruby 太旧了。Redmine 会欺骗您,最新版本的 Redmine 适用于 Ruby 1.8.7,但我因为这个谎言浪费了大约两个小时。我的 Redmine 在 CentOS 6.4 上运行,使用的是 ruby​​ 1.9.3p385。尝试更新到该版本,您可能能够运行 rake 命令。按如下方式更新 Ruby:

http://www.ruby-lang.org/en/downloads/(查看第三方工具/RVM 部分)。

答案2

我尝试了上述两种解决方案,只有编辑数据库的选项有效。升级到 Ruby 2.1 并没有改变任何东西。但是,我可以说我不需要“drop index”命令,并且根据我失败的迁移次数,我有时需要删除成员角色表。我最后、最可重复的解决方案是在迁移期间不手动编辑数据库,而是编辑迁移文件本身,以便在正确的时间点删除 inherit_members 字段并在正确的时间点重新添加。要编辑的两个文件是:

  • db/migrate/20130202090625_add_projects_inherit_members.rb
    • 需要在添加列remove_column :projects, :inherit_members之前添加行projects
  • db/migrate/105_build_projects_tree.rb
    • 需要添加add_column :projects, :inherit_members, :boolean, :default => false, :null => false之前Project.rebuid_tree

经过这两个更改后,无需打开 mysql shell 就可以一次性完成完整的升级过程(当然,最初的创建数据库、用户和权限命令除外)。

答案3

我在 Centos 6.2 上遇到了完全相同的错误,当时我尝试将 Ruby 1.9.3-p392 从 0.8.x 升级到 2.3.0。最新版本的 Ruby 和 gem。我这样做了。

更改数据库。您可能不必删除索引,我因为处于半升级状态而删除了索引。

更改表项目添加列 inherit_members boolean 默认 false;
更新项目设置 inherit_members = false;

删除索引changesets_repos_scmid;
删除索引index_attachments_on_author_id;
删除索引index_attachments_on_container_id_and_container_type;
删除索引index_attachments_on_created_on;
删除索引index_auth_sources_on_id_and_type;
删除索引index_boards_on_last_message_id;
删除索引index_changesets_on_committed_on;
删除索引index_changesets_on_repository_id;
删除索引index_changesets_on_user_id;
删除索引index_comments_on_author_id;
删除索引index_comments_on_commented_id_and_commented_type;
删除索引index_custom_fields_on_id_and_type;
删除索引index_custom_fields_projects_on_custom_field_id_and_project_id;
删除索引index_custom_fields_trackers_on_custom_field_id_and_tracker_id;
删除索引index_custom_values_on_custom_field_id;
删除索引index_documents_on_category_id;
删除索引index_documents_on_created_on;
删除索引index_issue_categories_on_assigned_to_id;
删除索引index_issue_relations_on_issue_from_id;
删除索引index_issue_relations_on_issue_from_id_and_issue_to_id;
删除索引index_issue_relations_on_issue_to_id;
删除索引index_issues_on_assigned_to_id;
删除索引index_issues_on_author_id;
删除索引index_issues_on_category_id;
删除索引index_issues_on_created_on;
删除索引index_issues_on_fixed_version_id;
删除索引 index_issues_on_priority_id
删除索引index_issues_on_priority_id;
删除索引index_issues_on_status_id;
删除索引index_issues_on_tracker_id;
删除索引index_issue_statuses_on_is_closed;
删除索引index_issue_statuses_on_is_default;
删除索引index_issue_statuses_on_position;
删除索引index_journals_on_created_on;
删除索引index_journals_on_journalized_id;
删除索引index_journals_on_user_id;
删除索引index_members_on_project_id;
删除索引index_members_on_user_id;
删除索引index_members_on_user_id_and_project_id;
删除索引index_messages_on_author_id;
删除索引index_messages_on_created_on;
删除索引index_messages_on_last_reply_id;
删除索引index_news_on_author_id;
删除索引index_news_on_created_on;
删除索引index_queries_on_project_id;
删除索引index_queries_on_user_id;
删除索引index_repositories_on_project_id;
删除索引index_settings_on_name;
删除索引index_time_entries_on_activity_id;
删除索引index_time_entries_on_created_on;
删除索引index_time_entries_on_user_id;
删除索引index_tokens_on_user_id;
删除索引index_user_preferences_on_user_id;
删除索引index_users_on_auth_source_id;
删除索引index_users_on_id_and_type;
删除索引index_users_on_type;
删除索引index_watchers_on_user_id;
删除索引index_watchers_on_watchable_id_and_watchable_type;
删除索引index_wiki_contents_on_author_id;
删除索引index_wiki_content_versions_on_updated_on;
删除索引index_wiki_pages_on_parent_id;
删除索引index_wiki_pages_on_wiki_id;
删除索引index_wiki_redirects_on_wiki_id;
删除索引index_workflows_on_new_status_id;
删除索引index_workflows_on_old_status_id;
删除索引index_workflows_on_role_id;
删除索引projects_trackers_unique;
删除索引 tokens_value;
删除索引watchers_user_id_type;

cd /usr/local/redmine
rake tmp:缓存:清除
rake tmp:会话:清除
rake 生成秘密令牌
rake --trace db:migrate RAILS_ENV=production


那个会因为最初抱怨不存在的列而失败,就像在父问题中一样。
“错误:关系“projects”的列“inherit_members”已经存在”
删除该列并再次迁移:

更改表项目删除列inherit_members;

cd /usr/local/redmine
rake --trace db:migrate RAILS_ENV=production

没有错误地完成。

相关内容