I was working on a project today for a client and after the initial research I realized that the project actually warranted an entire sub project account in Redmine. The reasoning behind this was even though the project would be using the same Ruby project code as the primary project this specific side project would need to allow access to the tickets for one of our partners. The easiest way to allow the partners accounts access to only a specific set of tickets, their own wiki, etc. would be to generate a sub Redmine project underneath of the primary Redmine project. So obviously the first thing to do was to add the project so I could start configuring it and this is where I ran into the initial issue. I received an internal server error when attempting to add the sub project within Redmine. Below I describe the issue, what I think caused the issue, and the end resolution that allowed me to start adding sub projects within Redmine again.
Internal Error Adding Redmine SubProject:
As you can see in the above image the error was not descriptive at all and only stated, “Internal Error: An error occurred on the page you were trying to access. If you continue to experience problems please contact your redMine administrator for assistance.” So the first place to look to see details about the issue was the Ruby project production.log file associated with this Redmine installation and below are the details from the log after attempting to save a new SubProject within Redmine.
Redmine Production Log File Error After Attempting To Add A Redmine SubProject:
- Processing ProjectsController#add (for 192.168.1.55 at 2010-03-30 15:26:16) [POST]
- Session ID: 33f150c330dbcca3b8e4a4cee3334c63
- Parameters: {"commit"=>"Save", "enabled_modules"=>["issue_tracking", "documents", "files", "wiki"], "project"=>{"issue_custom_field_ids"=>[""], "name"=>"Health Project", "tracker_ids"=>["3", "1", "2", "4", "5", "7", ""], "description"=>"Project related to the company A and company B partnership. ", "homepage"=>"", "is_public"=>"0", "identifier"=>"health-project", "parent_id"=>"2"}, "action"=>"add", "authenticity_token"=>"90555879c9d333a3e48b3333b12cccf0b82bb2a0", "controller"=>"projects"}
- ActiveRecord::StatementInvalid (Mysql::Error: Unknown column 'projects_count' in 'field list': UPDATE `projects` SET `projects_count` = COALESCE(`projects_count`, 0) + 1 WHERE (`id` = 2) ):
- /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:302:in `execute'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:167:in `update_sql'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:317:in `update_sql'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:49:in `update_without_query_dirty'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:19:in `update'
- /vendor/rails/activerecord/lib/active_record/base.rb:752:in `update_all'
- /vendor/rails/activerecord/lib/active_record/base.rb:837:in `update_counters_without_lock'
- /vendor/rails/activerecord/lib/active_record/locking/optimistic.rb:143:in `update_counters'
- /vendor/rails/activerecord/lib/active_record/base.rb:856:in `increment_counter'
- /vendor/rails/activerecord/lib/active_record/associations.rb:928:in `belongs_to_counter_cache_after_create_for_parent'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in `send'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in `evaluate_method'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:161:in `call'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
- /vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `run_callbacks'
- /vendor/rails/activerecord/lib/active_record/callbacks.rb:298:in `callback'
- /vendor/rails/activerecord/lib/active_record/callbacks.rb:221:in `create_without_timestamps'
- /vendor/rails/activerecord/lib/active_record/timestamp.rb:29:in `create'
- /vendor/rails/activerecord/lib/active_record/base.rb:2483:in `create_or_update_without_callbacks'
- /vendor/rails/activerecord/lib/active_record/callbacks.rb:207:in `create_or_update'
- /vendor/rails/activerecord/lib/active_record/base.rb:2211:in `save_without_validation'
- /vendor/rails/activerecord/lib/active_record/validations.rb:911:in `save_without_dirty'
- /vendor/rails/activerecord/lib/active_record/dirty.rb:75:in `save_without_transactions'
- /vendor/rails/activerecord/lib/active_record/transactions.rb:106:in `save'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
- /vendor/rails/activerecord/lib/active_record/transactions.rb:79:in `transaction'
- /vendor/rails/activerecord/lib/active_record/transactions.rb:98:in `transaction'
- /vendor/rails/activerecord/lib/active_record/transactions.rb:106:in `save'
- /vendor/rails/activerecord/lib/active_record/transactions.rb:118:in `rollback_active_record_state!'
- /vendor/rails/activerecord/lib/active_record/transactions.rb:106:in `save'
- /app/controllers/projects_controller.rb:76:in `add'
- /vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `send'
- /vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `perform_action_without_filters'
- /vendor/rails/actionpack/lib/action_controller/filters.rb:579:in `call_filters'
- /vendor/rails/actionpack/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'
- /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /vendor/rails/actionpack/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'
- /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
- /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
- /vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'
- /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
- /vendor/rails/actionpack/lib/action_controller/base.rb:529:in `send'
- /vendor/rails/actionpack/lib/action_controller/base.rb:529:in `process_without_filters'
- /vendor/rails/actionpack/lib/action_controller/filters.rb:568:in `process_without_session_management_support'
- /vendor/rails/actionpack/lib/action_controller/session_management.rb:130:in `process'
- /vendor/rails/actionpack/lib/action_controller/base.rb:389:in `process'
- /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:in `handle_request'
- /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in `dispatch'
- /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `synchronize'
- /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `dispatch'
- /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'
- /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:35:in `dispatch'
- /var/lsws/fcgi-bin/RailsRunner.rb:100
- Rendering /home/web/redmine/public/500.html (500 Internal Server Error)
The Missing projects_count Column In The MySQL projects Table:
In the above exception message it is clear to see there appears to be an issue with the projects_count column located in the MySQL projects table. After a bit of research I was able to find out that the projects_count column was added in the initial migration, located in the file 001_setup.rb, which was run when I first installed Redmine. I was also able to determine that somewhere between my initial Redmine installation and Redmine version 0.9.3 the projects_count column was removed because it was no longer used by Redmine. I was unable to pinpoint exactly why the projects_count column was missing but I was able to see that in the latest version a migration was included to remove the projects_count column from the projects table using migration 106 which was completed in the 106_remove_projects_projects_count.rb file. Somehow I was stuck in a state between where Redmine was using the projects_count column and where they decided to stop using it. The interesting point is I had a two different Redmine installations (versions 0.8.3 and 0.8.7) that both had the same issue.
How To Resolve The projects_count Exception Error:
I decided to take my chances and after backing up all of the files and the database I decided to upgrade Redmine to the latest stable release which at the time was Redmine version 0.9.3. After working through some separate issues not related to the projects_count column Redmine was updated successfully and I attempted to add a SubProject of an already existing Redmine Project and this time it saved without issue. My suggestion would be that if you are getting exceptions related to the projects_count column in the projects table that you upgrade to the latest stable Redmine version to resolve the issue.