Project

General

Profile

Help with db:migrate - seems to be missing tables/columns

Added by Amanda Zepeda almost 9 years ago

Hi,

I'm trying to put redmine 3.0.3 on a new linux server (Red Hat Enterprise Linux Server release 6.6, with Linux 2.6.32-279.11.1.el6.x86_64).
Output of RAILS_ENV=PRODUCTION bin/about:
sh: darcs: command not found
sh: hg: command not found
sh: bzr: command not found
Environment:
Redmine version 3.0.3.stable
Ruby version 2.2.2-p95 (2015-04-13) [x86_64-linux]
Rails version 4.2.1
Environment production
Database adapter Mysql2
SCM:
Subversion 1.6.11
Git 1.7.1
Filesystem
Redmine plugins:
no plugin installed
MySQL2 Server version: 5.1.73

I've followed these instructions for installation mostly: "Install Redmine on Centos 6.5 - 64 bit"
http://www.redmine.org/projects/redmine/wiki/Install_Redmine_25x_on_Centos_65_complete#Install-Apache-and-MySQL

After the db:migrate (RAILS_ENV=production rake db:migrate) and starting with the redmine:load_default_data I started getting errors as if I was missing tables and columns in the database; I have placed some examples of these errors below. I can manually add the tables and columns which is what has gotten me past many of the errors but they are still happening as I browse my instance of redmine. Clearly this level of repetitive errors is not "normal" and attempting to add the tables/columns manually can only get me so far since I am guessing; not to mention the time it takes!

So here are my general questions:
Am I installing the correct versions in the correct way based on the information above?
Why does it appear that my database is missing tables/columns? Is there a log file for the db:migrate so I can see what is happening during the migrate?
Is there an updated database diagram I can look and compare to?

---------------
Just a few examples of errors:
When trying to hit the URL for the first time:

Mysql2::Error: Table 'redmine.settings' doesn't exist: SHOW FULL FIELDS FROM `settings`
Completed 500 Internal Server Error in 3ms (ActiveRecord: 1.0ms)

ActiveRecord::StatementInvalid (Mysql2::Error: Table 'redmine.settings' doesn't exist: SHOW FULL FIELDS FROM `settings`):
app/models/setting.rb:186:in `check_cache'
app/controllers/application_controller.rb:100:in `user_setup'

-----later-----
NoMethodError (undefined method `passwd_changed_on' for #<AnonymousUser:0x00000004ce6ef0>):
app/controllers/application_controller.rb:150:in `force_logout_if_password_changed'

-----later-----
Mysql2::Error: Table 'redmine.enabled_modules' doesn't exist: SELECT `news`.* FROM `news` INNER JOIN `projects` ON `projects`.`id` = `news`.`project_id` WHERE (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='news')) ORDER BY news.created_on DESC LIMIT 5
Completed 500 Internal Server Error in 43ms (ActiveRecord: 2.7ms)

ActiveRecord::StatementInvalid (Mysql2::Error: Table 'redmine.enabled_modules' doesn't exist: SELECT `news`.* FROM `news` INNER JOIN `projects` ON `projects`.`id` = `news`.`project_id` WHERE (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='news')) ORDER BY news.created_on DESC LIMIT 5):
app/models/news.rb:84:in `latest'
app/controllers/welcome_controller.rb:22:in `index'
-----etc-----

When trying to login as admin:

NameError (undefined local variable or method `salt' for #<User:0x000000045aef98>):
app/models/user.rb:308:in `check_password?'
app/models/user.rb:212:in `try_to_login'
app/controllers/account_controller.rb:194:in `password_authentication'
app/controllers/account_controller.rb:189:in `authenticate_user'
app/controllers/account_controller.rb:40:in `login'

-----later-----
NoMethodError (undefined method `must_change_passwd?' for #<User:0x00000003f08018>):
app/models/user.rb:327:in `must_change_password?'
app/controllers/application_controller.rb:93:in `start_user_session'
app/controllers/application_controller.rb:182:in `logged_user='
app/controllers/account_controller.rb:256:in `successful_authentication'
app/controllers/account_controller.rb:203:in `password_authentication'
app/controllers/account_controller.rb:189:in `authenticate_user'
app/controllers/account_controller.rb:40:in `login'

And the list goes on and on until my most recent error below which I have been blocked by; I do not know what needs to be altered in the database to fix it.

When I try to go to My Page > Issues assigned to me I get:

Completed 500 Internal Server Error in 13ms (ActiveRecord: 0.8ms)

ActiveRecord::UnknownAttributeError (unknown attribute 'name' for IssueQuery.):
app/models/query.rb:232:in `initialize'
app/models/issue_query.rb:71:in `initialize'
app/helpers/queries_helper.rb:196:in `retrieve_query'
app/controllers/issues_controller.rb:46:in `index'

---------------------------
Thanks for any help!!! I am very new to this.


Replies (7)

RE: Help with db:migrate - seems to be missing tables/columns - Added by Leonel Iturralde almost 9 years ago

Hi,
When you ran db:migrate there were no errors? because at that moment all tables are created.
Try creating new database and run bundle exec rake db:migrate

RE: Help with db:migrate - seems to be missing tables/columns - Added by Amanda Zepeda almost 9 years ago

Hi,

So based on your advice I created a new DB following these instructions:
mysql --user=root --password=root_password_mysql
create database redmine_db character set utf8;
create user 'redmine_admin''localhost' identified by 'my_password';
grant all privileges on redmine_db.* to 'redmine_admin'
'localhost';

Changed my database.yml file:
production:
adapter: mysql2
database: redmine_db
host: localhost
username: redmine_admin
password: my_password
encoding: utf8

This is the output. Even though there are no errors, I still think it is missing some tables like "enabled_modules" and "user_preferences":

[root@c0007776 redmine]# RAILS_ENV=production bundle exec rake db:migrate
1 Setup: migrating =======================================================
-- create_table("attachments", {:force=>true})
> 0.0062s
-
create_table("auth_sources", {:force=>true})
> 0.0050s
-
create_table("custom_fields", {:force=>true})
> 0.0127s
-
create_table("custom_fields_projects", {:id=>false, :force=>true})
> 0.0091s
-
create_table("custom_fields_trackers", {:id=>false, :force=>true})
> 0.0094s
-
create_table("custom_values", {:force=>true})
> 0.0093s
-
create_table("documents", {:force=>true})
> 0.0056s
-
add_index("documents", ["project_id"], {:name=>"documents_project_id"})
> 0.0189s
-
create_table("enumerations", {:force=>true})
> 0.0059s
-
create_table("issue_categories", {:force=>true})
> 0.0063s
-
add_index("issue_categories", ["project_id"], {:name=>"issue_categories_project_id"})
> 0.0137s
-
create_table("issue_histories", {:force=>true})
> 0.0061s
-
add_index("issue_histories", ["issue_id"], {:name=>"issue_histories_issue_id"})
> 0.0107s
-
create_table("issue_statuses", {:force=>true})
> 0.0078s
-
create_table("issues", {:force=>true})
> 0.0144s
-
add_index("issues", ["project_id"], {:name=>"issues_project_id"})
> 0.0134s
-
create_table("members", {:force=>true})
> 0.0066s
-
create_table("news", {:force=>true})
> 0.0053s
-
add_index("news", ["project_id"], {:name=>"news_project_id"})
> 0.0207s
-
create_table("permissions", {:force=>true})
> 0.0057s
-
create_table("permissions_roles", {:id=>false, :force=>true})
> 0.0078s
-
add_index("permissions_roles", ["role_id"], {:name=>"permissions_roles_role_id"})
> 0.0112s
-
create_table("projects", {:force=>true})
> 0.0179s
-
create_table("roles", {:force=>true})
> 0.0177s
-
create_table("tokens", {:force=>true})
> 0.0088s
-
create_table("trackers", {:force=>true})
> 0.0076s
-
create_table("users", {:force=>true})
> 0.0055s
-
create_table("versions", {:force=>true})
> 0.0058s
-
add_index("versions", ["project_id"], {:name=>"versions_project_id"})
> 0.0115s
-
create_table("workflows", {:force=>true})
-> 0.0140s
1 Setup: migrated (0.5236s) ==============================================

2 IssueMove: migrating ===================================================
2 IssueMove: migrated (0.0139s) ========================================== 3 IssueAddNote: migrating ================================================
3 IssueAddNote: migrated (0.0194s) ======================================= 4 ExportPdf: migrating ===================================================
4 ExportPdf: migrated (0.0165s) ========================================== 5 IssueStartDate: migrating ==============================================
-- add_column(:issues, :start_date, :date)
> 0.0114s
-
add_column(:issues, :done_ratio, :integer, {:default=>0, :null=>false})
-> 0.0114s
5 IssueStartDate: migrated (0.0229s) ===================================== 6 CalendarAndActivity: migrating =========================================
6 CalendarAndActivity: migrated (0.0173s) ================================

RE: Help with db:migrate - seems to be missing tables/columns - Added by Leonel Iturralde almost 9 years ago

Hi,
is that all the output of db:migrate?
if yes then it seems to be incomplete. there must be a problem with db:migrate

RE: Help with db:migrate - seems to be missing tables/columns - Added by Amanda Zepeda almost 9 years ago

Yes, this is all the output. I also believe this is incomplete but I am not sure why.

Others I work with have encountered the same issues. It seems that the "schema.rb" file in <redmine path>/db (in my case /var/www/redmine/db/schema.rb) only lists those tables that you see in the above output.
If I go down another folder (/var/www/redmine/db/migrate) I see a whole bunch of .rb files but I don't know how to use them or even if I should. If these are supposed to be automatically included in the db:migrate then it is not working.

I am attaching my schema.rb file. Perhaps someone can compare with theirs to see if this file is missing anything.

schema.rb (10.3 KB) schema.rb

RE: Help with db:migrate - seems to be missing tables/columns - Added by Leonel Iturralde almost 9 years ago

Hi,
Try running
RAILS_ENV=production bundle exec rake db:migrate:reset

I uploaded my schema.rb for comparison.

schema.rb (32.4 KB) schema.rb

RE: Help with db:migrate - seems to be missing tables/columns - Added by Amanda Zepeda almost 9 years ago

Thanks, this started me on the right path. The command above did not work by itself; it simply reset my database to the tables that are in the schema.rb file which only contained the default ~24 tables.

So basically my schema.rb file never got updated with the additional rb file/classes in /var/www/redmine/db/migrate. There are some couple hundred or so classes that need to get loaded. My work around was this:

I dropped the tables to get a fresh start
/opt/apps/www/redmine/bin/rake db:drop

Created:
/opt/apps/www/redmine/bin/rake db:create

Migrated:
/opt/apps/www/redmine/bin/rake db:migrate

Then in order to get all of the new modifications, I performed this command for each rb file in the migrate path mentioned above.
/opt/apps/www/redmine/bin/rake db:migrate:up VERSION=001 --trace
/opt/apps/www/redmine/bin/rake db:migrate:up VERSION=002 --trace
/opt/apps/www/redmine/bin/rake db:migrate:up VERSION=003 --trace
etc... until the last ones...
/opt/apps/www/redmine/bin/rake db:migrate:up VERSION=20150113213955 --trace
/opt/apps/www/redmine/bin/rake db:migrate:up VERSION=20150208105930 --trace

This finally updated my schema.rb file and the database. My redmine is working now but I am not sure why it didn't work in the first place and required this work around.

Thanks for the help!

RE: Help with db:migrate - seems to be missing tables/columns - Added by Amanda Zepeda almost 9 years ago

One last note in case this is confusing to anyone - You may notice two different paths:
/var/www/redmine
/opt/apps/www/redmine

These are pointing to the same location as they are sym-linked.

    (1-7/7)