Rails 3-突然挂起迁移错误 [英] Rails 3 - suddenly pending migrations error

查看:77
本文介绍了Rails 3-突然挂起迁移错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我突然遇到一个奇怪的错误.当我尝试运行rake spec时,我会收到:

I suddenly met a strange error. When i try to run rake spec i recieve:

You have 2 pending migrations:
  20130405105004 CreateReports
  20130405113839 AddDocumentToReports

我不知道原因(我过去运行过迁移,所以我在数据库和schema.rb中都有数据).

I don't know the reason for that (i run migrations in the past so i have data in the database and 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

我该如何解决?

推荐答案

如果这是在开发环境中,并且数据库中没有重要数据,请运行

If this is on a dev environment and you have no important data in the db, then run

bundle exec rake db:migrate:reset

这将重建模式,但以牺牲所有数据为代价.

This will rebuild the schema, but at the cost of nuking all your data.

这篇关于Rails 3-突然挂起迁移错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆