2015-09-07 92 views
0

這是我在堆棧跟蹤控制檯中得到的錯誤。我還需要補充的是,這不起作用「rake db:migrate RAILS_ENV = development」。Rake中止錯誤,無法遷移。任何想法爲什麼?

activerecord (4.2.0) lib/active_record/migration.rb:393:in `check_pending!' 
    activerecord (4.2.0) lib/active_record/migration.rb:374:in `call' 
    actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
    activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call' 
    activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks' 
    activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks' 
    activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call' 
    actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call' 
    actionpack (4.2.0) 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.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged' 
    activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged' 
    railties (4.2.0) lib/rails/rack/logger.rb:20:in `call' 
    actionpack (4.2.0) 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.0)  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.0) lib/action_dispatch/middleware/static.rb:113:in `call' 
    rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
    railties (4.2.0) lib/rails/engine.rb:518:in `call' 
    railties (4.2.0) lib/rails/application.rb:164: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' 
    C:/row/ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
    C:/row/ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
    C:/row/ruby200/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 

這是錯誤開啓服務器,並試圖訪問我的網站時,我得到的,

ActiveRecord::PendingMigrationError 

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

這是我的移民文件,

class CreateFriendships < ActiveRecord::Migration 
    def change 
    create_table :friendships do |t| 
     class CreateFriendships 
      def self.up 
       create_table :friendships do |t| 
       t.integer :user_id, :friend_id 
       t.string :status 
       t.timestamps 
      end 
      end 
      def self.down 
       drop_table :friendships 
      end 
     end 

     t.timestamps null: false 
    end 
    end 
end 

,如果有任何其他代碼,你可能需要看看,請讓我知道!我會更新我的問題!

編輯:這是我的welcome_controller.rb,

class WelcomeController < ApplicationController 
    def welcome 
    @user = User.new 
    end 
end 

編輯:這是下面的錯誤,我得到

ArgumentError in WelcomeController#welcome 

Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type 

編輯:這是我的用戶模型,

class User < ActiveRecord::Base 
    has_secure_password 
    validates :first_name, :last_name, :email, presence: true, uniqueness: true 
    validates_inclusion_of :age, in: 10..100 
    validates :password, presence: true, length: { minimum: 4 }, allow_nil: true 
    has_many :posts 
    has_many :friends, :through => :friendships, :conditions => "status = 'accepted'" 
    has_many :requested_friends, :through => :friendships, :source => :friend, :conditions => "status = 'requested'", :order => "friendships.created_at" 
    has_many :pending_friends, :through => :friendships, :source => :friend, :conditions => "status = 'pending'", :order => "friendships.created_at" 
    has_many :friendships, :dependent => :destroy 
    has_attached_file :profile_picture, :styles => { :medium => "300x300>", :thumb => "100x100>" }, 
:default_url => "app/assets/images/missing.png", 
:path => ":rails_root/public/system/:class/:attachment/:id_partition/:style/:filename" 
    validates_attachment_content_type :profile_picture, :content_type => /\Aimage\/.*\Z/ 
end 
+0

您確定在遷移時關閉服務器嗎?因爲遷移不能通過服務器運行/ – Kiloreux

+0

我的意思是,它不會讓我鍵入代碼,除非服務器關閉。 –

+1

@Kiloreux _遷移不能用服務器running_完成 - 那是不正確的。 –

回答

1

我認爲你需要像這樣改變你的遷移文件,

class CreateFriendships < ActiveRecord::Migration 
def change 
    create_table :friendships do |t| 
     t.integer :user_id, :friend_id 
     t.string :status 
     t.timestamps null: false 
    end 
end 
end 

class CreateFriendships < ActiveRecord::Migration 
    def self.up 
    create_table :friendships do |t| 
     t.integer :user_id, :friend_id 
     t.string :status 
     t.timestamps 
    end 
    end 

    def self.down 
    drop_table :friendships 
    end 
end 

然後用rake db:migrate去跑步服務器之前。

and

在Rails 4中,通過範圍塊實現條件。所以你可以試試這個。

has_many :friends, -> { where "status = 'accepted'" }, :through => :friendships 

像你一樣,你必須改變所有攜帶:conditions的關係。 requested_friends和pending_friends。

+0

跟着你做了什麼,得到這個錯誤, WelcomeController中的ArgumentError#welcome –

+0

@usmanali;)謝謝你。 @Geno Lagana:'WelcomeController'中的錯誤。分享你的代碼。 –

+0

我編輯它,以便您現在可以看到該控制器 –

相關問題