rails 3'表中的mysql2已存在'如何删除?

时间:2012-12-13 10:16:46

标签: mysql database ruby-on-rails-3 ubuntu-12.04

我出于某种原因删除项目robin_offine,当我重新启动它并运行

rake db:create,它声称:

robin_offline_development already exists  
robin_offline_test already exists  

忽略它并添加名为events的迁移

如果rake db:migrate

Mysql2::Error: Table 'events' already exists(cuz i have done that last time)

问题是,我无法找到表格的位置

SHOW DATABASES;  
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |    
| test               |  
+--------------------+   
2 rows in set (0.00 sec)

甚至不知道要删除哪一个

抱歉,我是mysql的新手 系统是Ubuntu 12.04LTS

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

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: robin_offline_test
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock

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

我的迁移文件就是运行

rails g model events    
没什么特别的

develop.log

Connecting to database specified by database.yml
Connecting to database specified by database.yml
  [1m[36m (1.1ms)[0m  [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
Migrating to CreateEvents (20121213091145)
  [1m[35m (0.5ms)[0m  CREATE TABLE `events` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
Mysql2::Error: Table 'events' already exists: CREATE TABLE `events` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
Connecting to database specified by database.yml
  [1m[36m (1.1ms)[0m  [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
Migrating to CreateEvents (20121213091145)
  [1m[35m (0.5ms)[0m  CREATE TABLE `events` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
Mysql2::Error: Table 'events' already exists: CREATE TABLE `events` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
Connecting to database specified by database.yml
  [1m[36m (1.9ms)[0m  [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
Migrating to CreateEvents (20121213091145)
  [1m[35m (0.5ms)[0m  CREATE TABLE `events` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
Mysql2::Error: Table 'events' already exists: CREATE TABLE `events` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB

1 个答案:

答案 0 :(得分:0)

我刚跑

rake db:drop

再次进行迁移,一切顺利

rails db转到数据库并做任何你想做的事。