1
votes

I recently pulled some code and ran rspec. The tests passed with no problem. When I ran "rake db:migrate" and "rake db:prepare" however, I got an issue.

Now no rspec test passes, and every failure cites the same error:

Mysql2::Error: Table 'app_test.admins' doesn't exist: SHOW FULL FIELDS FROM `admins`

The thing is, that database name is not specified anywhere in the code. In database.yml, 'app_test' is specified, with no '.admins' suffix.

Similarly, when I run rails server, I get the following error:

Mysql2::Error: Table 'app_dev.admins' doesn't exist: SHOW FULL FIELDS FROM `admins`

Only 'app_dev' is specified in yml.

The rake commands (db:migrate, db:test:prepare, db:create, db:drop, etc.) are all modifying the database.yml specified databases, it's just that Rails is looking for databases with the '.admins' suffix. Where is this '.admins' suffix coming from and how can I remove it?

4
show your GemFile pleaseBenj

4 Answers

2
votes

app_test and app_dev are database names.

it's just that Rails is looking for databases with the '.admins' suffix.

Actually app_test.admins and app_dev.admins are tables that rails is looking for in the two databases. Couple of approaches that I would try:

rake db:create
rake db:migrate

or

rake db:schema:load
2
votes

The issue was as follows:

When I pulled the code, for whatever reason, the 'Admins' table disappeared from db/schema.rb. This table cannot be restored via rake:db:migrate because the migration that created it uses t.database_authenticatable, which has been deprecated and no longer works with the Devise gem. Because we're building on legacy code, we only run rake db:migrate on recently changed migrations, never from an empty database (for an empty database, we use rake db:schema:load).

Since the table was missing from db/schema.rb it would not be restored even if I used rake db:schema:load. To fix the issue, I had to use git reset to revert to an old version of db/schema.rb.

To fix the Devise deprecation issue so that you can run all of your migrations, go here - https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

0
votes

Is rake db:prepare a valid command? Did you try rake db:create:all?

0
votes

Is it possible that your rails-settings-cached is configured to use admin table? Do you remember typing rails g settings admin?

Check in your models for a admin.rb file, or for a model that derivates from RailsSettings::CachedSettings

Check your initializers for the same gem as well