突然遇到一个奇怪的错误。当我尝试运行 rake spec
时,我收到:
You have 2 pending migrations:
20130405105004 CreateReports
20130405113839 AddDocumentToReports
我不知道这样做的原因(我过去运行过迁移,所以我在数据库和 schema.rb 中有数据)。
这是rake spec --trace
:
** Invoke spec (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
You have 2 pending migrations:
20130405105004 CreateReports
20130405113839 AddDocumentToReports
Run "rake db:migrate" to update your database then try again.
这是rake db:migrate:status
:
...
up 20121210112419 Create simple captcha data
up 20130214110545 Add weeknum to alerts
down 20130405105004 Create reports
down 20130405113839 Add document to reports
up 20121018133601 *** NO FILE ***
up 20121018163051 *** NO FILE ***
up 20121024124111 *** NO FILE ***
这里是 rake db:migrate
== CreateReports: migrating ==================================================
-- create_table(:reports)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'reports' already exists: CREATE TABLE `reports` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `user_id` int(11), `ready_status` tinyint(1) DEFAULT 0, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
Tasks: TOP => db:migrate
我该如何解决?
最佳答案
如果这是在开发环境中并且数据库中没有重要数据,则运行
bundle exec rake db:migrate:reset
这将重建模式,但代价是破坏所有数据。
关于mysql - Rails 3 - 突然挂起的迁移错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15902940/