Ruby on Rails-PendingMigrationError吗?

时间:2018-07-15 18:54:25

标签: ruby-on-rails ruby puma

我刚刚开始使用RoR构建的现有项目,这对我来说是全新的。

为了有所作为,我尝试使用rails s启动项目,但是在浏览器中出现以下错误:

ActiveRecord::PendingMigrationError 

Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development

运行此命令时,我会在控制台中看到以下内容,但浏览器只是刷新回相同的错误?

ansi: 'gem install win32console' to use color on Windows
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate RAILS_ENV=development

):

activerecord (5.0.0.1) lib/active_record/migration.rb:572:in `check_pending!'
activerecord (5.0.0.1) lib/active_record/migration.rb:548:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
bugsnag (5.1.0) lib/bugsnag/rack.rb:34:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.3.1) lib/web_console/middleware.rb:131:in `call_app'
web-console (3.3.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.3.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.3.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
request_store (1.4.0) lib/request_store/middleware.rb:19:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
railties (5.0.0.1) lib/rails/engine.rb:522:in `call'
puma (3.6.0) lib/puma/configuration.rb:225:in `call'
puma (3.6.0) lib/puma/server.rb:578:in `handle_request'
puma (3.6.0) lib/puma/server.rb:415:in `process_client'
puma (3.6.0) lib/puma/server.rb:275:in `block in run'
puma (3.6.0) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

如果运行rails db:migrate RAILS_ENV=development命令,将得到以下内容,但我不认识:

ansi: 'gem install win32console' to use color on Windows
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
== 20161205141923 AddLastSeenAtToUsers: migrating =============================
-- add_column(:users, :last_seen_at, :datetime)
   -> 0.0020s
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column users.deleted_at does not exist
LINE 1: SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS ...
                                            ^
: SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL
C:/projectName/db/migrate/20161205141923_add_last_seen_at_to_users.rb:5:in `change'
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column users.deleted_at does not exist
LINE 1: SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS ...
                                            ^
: SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL
C:/projectName/db/migrate/20161205141923_add_last_seen_at_to_users.rb:5:in `change'
PG::UndefinedColumn: ERROR:  column users.deleted_at does not exist
LINE 1: SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS ...
                                            ^
C:/projectName/db/migrate/20161205141923_add_last_seen_at_to_users.rb:5:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

正如我所说的,我是RoR的新手,所以我真的不确定什么地方出了什么问题,怎么回事,或者-显然-如何解决。

我已经尝试使用Google搜索,但是我只能找到rake db:drop/create/migrate,这无济于事。

有人想要了解最新情况吗?

谢谢

2 个答案:

答案 0 :(得分:1)

根据您的迁移错误,在20161205141923_add_last_seen_at_to_users.rb中进行的db/migrations迁移中,您需要在add_column :users, :deleted_at, :datetimedef change下添加def up(具体取决于您的Rails版本)

此列也可能是在以后的迁移中创建的,因此您希望在添加此行后查看它在哪里/是否中断。

答案 1 :(得分:0)

您需要运行迁移,以使schema.rb中的时间戳等于上一次迁移的时间戳。

如果已设置数据库,请运行命令rake db:migrate

否则,

rake db:create #Create Database rake db:migrate #Run all migrations rake db:seed #Load data from seeds.rb file

在设置数据库和执行迁移以安装运行项目所需的所有gem之前,运行bundle install