Mysql2 ::错误:表'对话'已经存在

时间:2014-07-28 05:28:37

标签: ruby-on-rails gem migration

尝试更新gem(邮箱)并将其删除后,我收到此错误。

Mysql2 ::错误:表'对话'已经存在:CREATE TABLE conversationsid int(11)DEFAULT NULL auto_increment PRIMARY KEY,subject varchar(255)DEFAULT'' ,created_at datetime NOT NULL,updated_at datetime NOT NULL)

我试过了:

  1. Bundle exec rake db:migrate rollback then rake db:migrate
  2. Bundle exec rake db:migrate v = xxxxxxxx then rake db:migrate
  3. 摆脱迁移文件(虽然有效,但我不喜欢只删除代码)
  4. 我不想丢失我的数据并放弃表格。 有什么想法吗?

    更新

    Rake db:migrate:status
    
       up     20140526010413  Adduserfollowme to users
       up     20140703193119  Add vote weight to votes
       up     20140713211140  Add partime to user
       up     20140716024440  Add devise to admin users
       up     20140716024510  Create active admin comments
       up     20140727042518  ********** NO FILE **********
       up     20140727051902  Add slug to activities
      down    20140728031732  Create mailboxer.mailboxer engine
      down    20140728031733  Add notified object.mailboxer engine
      down    20140728031734  Add notification code.mailboxer engine
      down    20140728031735  Add attachments.mailboxer engine
      down    20140728031736  Rename receipts read.mailboxer engine
      down    20140728031737  Add global notification support.mailboxer engine
    
    rake db:rollback
    
    ==  AddSlugToActivities: reverting ============================================
    -- remove_index("activities", {:column=>:slug})
       -> 0.0215s
    -- remove_column("activities", :slug)
       -> 0.0342s
    ==  AddSlugToActivities: reverted (0.0559s) ===================================
    
    Rake db:migrate
    
    ==  AddSlugToActivities: migrating ============================================
    -- add_column(:activities, :slug, :string)
       -> 0.0266s
    -- add_index(:activities, :slug)
       -> 0.0104s
    ==  AddSlugToActivities: migrated (0.0373s) ===================================
    
    ==  CreateMailboxer: migrating ================================================
    -- create_table(:conversations)
    rake aborted!
    StandardError: An error has occurred, all later migrations canceled:
    
    Mysql2::Error: Table 'conversations' already exists: CREATE TABLE `conversations` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `subject` varchar(255) DEFAULT '', `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:in `create_table'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/foreigner-1.6.1/lib/foreigner/connection_adapters/abstract/schema_statements.rb:14:in `create_table'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:432:in `create_table'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in `block in method_missing'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in `block in say_with_time'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in `say_with_time'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:in `method_missing'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:334:in `method_missing'
    /home/bill/apps/woomatch/releases/20140728100705/db/migrate/20140728031732_create_mailboxer.mailboxer_engine.rb:6:in `up'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:370:in `up'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in `block in migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in `migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:in `migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in `call'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in `ddl_transaction'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in `block in migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in `each'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in `migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:in `up'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in `migrate'
    /home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
    Tasks: TOP => db:migrate
    

    接下来我该怎么做?

1 个答案:

答案 0 :(得分:1)

没有rake db:migrate rollback,只有rake db:rollback 尝试使用rake db:migrate:status,然后使用rake db:rollback使不需要的迁移失效。

有时候,当“出现问题”并且你们进行了大量的迁移回滚时,有必要对某些行进行注释,进行迁移\回滚并再次对其进行修改。

如果它不起作用,请尝试显示失败的迁移代码