2015-09-07 66 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

我编辑它,以便您现在可以看到该控制器 –

相关问题