无法运行Rails迁移-ActiveRecord :: StatementInvalid:Mysql2 :: Error表不存在

时间:2018-10-15 19:26:27

标签: mysql ruby-on-rails activerecord database-migration

我正在尝试为Rails应用设置开发环境,但由于出现以下错误,因此无法运行迁移:

D, [2018-10-15T19:09:17.732136 #1] DEBUG -- :   Category Load (0.6ms)  SELECT `categories`.* FROM `categories` WHERE (categories.parent_id IS NULL)
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'mysite_dev.categories' doesn't exist: SELECT `categories`.* FROM `categories` WHERE (categories.parent_id IS NULL)
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query'
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query'
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt'
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:317:in `block in execute'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:317:in `execute'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/mysql2_adapter.rb:217:in `execute'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/mysql2_adapter.rb:221:in `exec_query'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:356:in `select'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/querying.rb:39:in `find_by_sql'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation.rb:639:in `exec_queries'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation.rb:515:in `load'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation.rb:243:in `to_a'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation/delegation.rb:46:in `map'
/usr/src/app/app/routing/categories_constraint.rb:4:in `<class:CategoriesConstraint>'
/usr/src/app/app/routing/categories_constraint.rb:3:in `<top (required)>'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:457:in `load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:457:in `block in load_file'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:647:in `new_constants_in'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:456:in `load_file'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:354:in `require_or_load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:494:in `load_missing_constant'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:184:in `const_missing'
/usr/src/app/config/routes.rb:334:in `block in <top (required)>'
/usr/local/bundle/gems/actionpack-4.2.10/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
/usr/local/bundle/gems/actionpack-4.2.10/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
/usr/local/bundle/gems/actionpack-4.2.10/lib/action_dispatch/routing/route_set.rb:410:in `draw'
/usr/src/app/config/routes.rb:1:in `<top (required)>'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `block in load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:40:in `each'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:16:in `reload!'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/file_update_checker.rb:75:in `execute'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:27:in `updater'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `run'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application.rb:352:in `initialize!'
/usr/src/app/config/environment.rb:5:in `<top (required)>'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application.rb:328:in `require_environment!'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:424:in `exec'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:27:in `dispatch'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:18:in `start'
/usr/local/bundle/gems/bundler-1.16.6/exe/bundle:30:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-1.16.6/exe/bundle:22:in `<top (required)>'
/usr/local/bundle/bin/bundle:104:in `load'
/usr/local/bundle/bin/bundle:104:in `<main>'
Mysql2::Error: Table 'mysite_dev.categories' doesn't exist
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query'
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query'
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt'
/usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:317:in `block in execute'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:317:in `execute'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/mysql2_adapter.rb:217:in `execute'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/mysql2_adapter.rb:221:in `exec_query'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:356:in `select'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/querying.rb:39:in `find_by_sql'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation.rb:639:in `exec_queries'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation.rb:515:in `load'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation.rb:243:in `to_a'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/relation/delegation.rb:46:in `map'
/usr/src/app/app/routing/categories_constraint.rb:4:in `<class:CategoriesConstraint>'
/usr/src/app/app/routing/categories_constraint.rb:3:in `<top (required)>'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:457:in `load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:457:in `block in load_file'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:647:in `new_constants_in'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:456:in `load_file'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:354:in `require_or_load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:494:in `load_missing_constant'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:184:in `const_missing'
/usr/src/app/config/routes.rb:334:in `block in <top (required)>'
/usr/local/bundle/gems/actionpack-4.2.10/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
/usr/local/bundle/gems/actionpack-4.2.10/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
/usr/local/bundle/gems/actionpack-4.2.10/lib/action_dispatch/routing/route_set.rb:410:in `draw'
/usr/src/app/config/routes.rb:1:in `<top (required)>'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `block in load'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:40:in `each'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:16:in `reload!'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/file_update_checker.rb:75:in `execute'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:27:in `updater'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `run'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application.rb:352:in `initialize!'
/usr/src/app/config/environment.rb:5:in `<top (required)>'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application.rb:328:in `require_environment!'
/usr/local/bundle/gems/railties-4.2.10/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:424:in `exec'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:27:in `dispatch'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:18:in `start'
/usr/local/bundle/gems/bundler-1.16.6/exe/bundle:30:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-1.16.6/exe/bundle:22:in `<top (required)>'
/usr/local/bundle/bin/bundle:104:in `load'
/usr/local/bundle/bin/bundle:104:in `<main>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => environment
(See full trace by running task with --trace)

我正在使用Docker Ruby映像2.3.1版。

我尝试过rake db:schema:load,试图删除db,再次创建它,运行迁移,但是总是相同的错误。

知道为什么会这样吗?

0 个答案:

没有答案