StandardError:发生错误,所有后来的迁移都被取消:Mysql2 :: Error:表' hiredjob_development.admins'不存在:

时间:2016-02-05 06:33:32

标签: ruby-on-rails ruby angularjs devise database-migration

我是一名新的ROR开发人员。我们正在使用Rails和AngularJS开发应用程序。我试图做的简要背景:    另一位开发人员开发了一个名为hiredjob的应用程序(部分)。我必须继续开发他的应用程序,将应用程序的名称更改为hiredtoday,并将所有模型从admin_X更改为X.以下是我遵循的步骤顺序:    方法1:

  1. 将旧的hiredjob应用程序复制到今天聘用的新应用程序。

  2. 删除所有db / migrate。

  3. rails generate devise admin。

  4. rake db:migrate提供错误

  5. 来自rake db:migrate

    错误:

    home/arshi/.rvm/gems/ruby-2.2.3/gems/devise-
    3.5.2/lib/devise/rails/routes.rb:485:in `raise_no_devise_method_error!': Admin does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError)
    

    在互联网上搜索上述解决方案后,我在devise_for :admins

    中发表评论config/route.rb
    1. 在运行rake db:之后再次迁移我遇到了错误。
    2. 错误如下:

      StandardError: An error has occurred, all later migrations canceled:
      
      Mysql2::Error: Table 'hiredjob_development.admins' doesn't exist: ALTER TABLE 'admins' ADD 'email' varchar(255) DEFAULT '' NOT NULL/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `execute'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:573:in `block (3 levels) in <class:Table>'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `each'
          /home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `block (2 levels) in <class:Table>'
      

      注意:我也尝试过运行:rake db:drop db:create db:migrate。但仍然无效。

1 个答案:

答案 0 :(得分:1)

我认为您收到此错误,因为设计取决于已创建的表。你需要:

1)删除设计迁移

2)编写迁移以创建管理员表http://guides.rubyonrails.org/active_record_migrations.html#creating-a-table

3)重新设计迁移。