当我输入 rails s 访问 http://localhost:3000/ 时 出错误
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
Rails.root: C:/Users/zmk pc/blog
Application Trace | Framework Trace | Full Trace
activerecord (4.2.3) lib/active_record/migration.rb:392:in `check_pending!'
activerecord (4.2.3) lib/active_record/migration.rb:373:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.3) lib/rails/engine.rb:518:in `call'
railties (4.2.3) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
D:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
D:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
D:/Ruby21-x64/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
按照提示,我停止 rails 输入 rake db:migrate RAILS_ENV=development 弹出错误
== 20150906003155 CreateArticles: migrating ===================================
-- create_table(:articles)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'articles' already exists: CREATE TABLE `articles` (`id` in
t(11) auto_increment PRIMARY KEY, `content` text, `created_at` datetime NOT NULL
, `updated_at` datetime NOT NULL) ENGINE=InnoDBC:/Users/zmk pc/blog/db/migrate/2
0150906003155_create_articles.rb:3:in `change'
D:in `migrate'
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'articles' already exists:
CREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `content` text
, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
C:/Users/zmk pc/blog/db/migrate/20150906003155_create_articles.rb:3:in `change'
D:in `migrate'
Mysql2::Error: Table 'articles' already exists
C:/Users/zmk pc/blog/db/migrate/20150906003155_create_articles.rb:3:in `change'
D:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
\blog\db\migrate\20150906003155_create_articles.rb 的代码如下
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.varchar :name
t.varchar :title
t.text :content
t.timestamps null: false
end
end
end
以下是我整个 blog 文件夹的下载地址 http://pan.baidu.com/s/1bnqbXmR
求高手指点~!