rake db:migrate - Mysql2 :: Error:Table' database_development.locations'不存在:从`locations`显示完整的字段

时间:2016-07-18 06:13:41

标签: mysql ruby-on-rails ruby ubuntu-server

Rails 3.2.2

ruby​​ 2.0.0

ubuntu 16.04

myssql server:

版本:5.7.12-0ubuntu1.1

版本:5.7.12-0ubuntu1

版本:5.7.11-0ubuntu6

我运行迁移,显示错误:(见下面的日志)

当我进入mysql控制台并选择所有数据库时,在当前列表中有我的数据库。

我试过从另一台电脑上运行迁移,ubuntu 14.04,mysql服务器:5.5.49,一切都运行没有错误。

如何解决这个问题?谢谢你提前

的database.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: projectname_development
  username: root
  password: "123" 
  socket: /var/run/mysqld/mysqld.sock


test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: projectname_test
  pool: 5
  username: root
  password: 123 
  socket: /var/run/mysqld/mysqld.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: projectname_production
  pool: 5
  username: root
  password: 123
  socket: /var/run/mysqld/mysqld.sock


Warning: Error loading /home/user/projects/projectname/app/models/country.rb:
Mysql2::Error: Table 'projectname_development.locations' doesn't exist: SHOW FULL FIELDS FROM `locations`
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-mini-profiler-0.9.7/lib/patches/db/mysql2.rb:20:in `query'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-mini-profiler-0.9.7/lib/patches/db/mysql2.rb:20:in `query'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `block in execute'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/mysql2_adapter.rb:213:in `execute'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:259:in `execute_and_free'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:426:in `columns'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/model_schema.rb:229:in `yield'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/model_schema.rb:229:in `columns'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/model_schema.rb:238:in `columns_hash'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/inheritance.rb:19:in `descends_from_active_record?'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/inheritance.rb:25:in `finder_needs_type_condition?'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/base.rb:455:in `relation'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/scoping/named.rb:37:in `scoped'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/querying.rb:9:in `order'
/home/user/projects/projectname/app/models/country.rb:16:in `<class:Country>'
/home/user/projects/projectname/app/models/country.rb:15:in `<top (required)>'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:469:in `load'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:469:in `block in load_file'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:639:in `new_constants_in'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:468:in `load_file'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:353:in `require_or_load'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:192:in `block in const_missing'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:190:in `each'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:190:in `const_missing'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.5.2/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/inflector/methods.rb:229:in `each'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/inflector/methods.rb:229:in `constantize'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/context.rb:64:in `block (2 levels) in load_models'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/context.rb:54:in `each'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/context.rb:54:in `block in load_models'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/context.rb:53:in `each'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/context.rb:53:in `load_models'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/context.rb:15:in `prepare'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx.rb:82:in `block in context'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx.rb:79:in `synchronize'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx.rb:79:in `context'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thinking-sphinx-2.0.14/lib/thinking_sphinx/active_record.rb:166:in `define_index'
/home/user/projects/projectname/app/models/group.rb:96:in `<class:Group>'
/home/user/projects/projectname/app/models/group.rb:35:in `<top (required)>'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:469:in `load'
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:469:in `block in load_file'
/home/user/.rbenv/versions/2.0.0-

1 个答案:

答案 0 :(得分:0)

我认为您已编写了用于创建位置表和向列添加列的迁移。

在向列表添加列时,您的迁移失败,如错误日志所示。

第1步: 复制创建位置表迁移文件的时间戳(不添加列时间戳)。

第2步: 在schema_migrations表中搜索并从中删除该记录。

而不是rake db:migrate