2015-12-02 30 views
0

我曾經使用sqlite作爲我的Rails應用程序的數據庫,然後使用Postgresql對其進行了更改,之後我嘗試添加新的遷移時開始出現錯誤。在Rails項目中遷移的參數錯誤

錯誤

$ rake db:migrate --trace 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Execute db:load_config 
** Execute db:migrate 
    rake aborted! 
    ArgumentError: wrong number of arguments (1 for 4..5) 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:99:in `initialize' 
    /Library/Ruby/Gems/2.0.0/gems/spatial_adapter-1.2.0/lib/spatial_adapter/postgresql.rb:71:in `new' 
    /Library/Ruby/Gems/2.0.0/gems/spatial_adapter-1.2.0/lib/spatial_adapter/postgresql.rb:71:in `create_table' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/schema_migration.rb:29:in `create_table' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:822:in `initialize_schema_migrations_table' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/migration.rb:922:in `initialize' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `new' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate' 
    /Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain' 
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run' 
    /Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>' 
    /usr/local/bin/rake:23:in `load' 
    /usr/local/bin/rake:23:in `<main>' 
    Tasks: TOP => db:migrate 

_create_users.rb <的ActiveRecord ::遷移

def change 
create_table :users do |t| 
    t.string :name 
    t.string :email 

    t.timestamps null: false 
end 

_microposts.rb <的ActiveRecord ::遷移

def change 
create_table :microposts do |t| 
    t.text :content 
    t.references :user, index: true, foreign_key: true 

    t.timestamps null: false 
end 
add_index :microposts, [:user_id, :created_at] 
end 

AddIndexToUsersEmail <的ActiveRecord ::遷移

def change 
    add_index :users, :email, unique: true 
    end 

AddPasswordDigestToUsers <的ActiveRecord ::遷移

def change 
     add_column :users, :password_digest, :string 
    end 

AddRememberDigestToUsers <的ActiveRecord ::遷移

def change 
     add_column :users, :remember_digest, :string 
    end 

AddAdminToUsers <的ActiveRecord ::遷移

 def change 
     add_column :users, :admin, :boolean 
    end 

AddActivationToUsers <的ActiveRecord ::遷移

 def change 
      add_column :users, :activation_digest, :string 
      add_column :users, :activated, :boolean, default: false 
      add_column :users, :activated_at, :datetime 
    end 

CreateRelationships <的ActiveRecord ::遷移

 def change 
create_table :relationships do |t| 
    t.integer :follower_id 
    t.integer :followed_id 

    t.timestamps null: false 
    end 
    add_index :relationships, :follower_id 
    add_index :relationships, :followed_id 
    add_index :relationships, [:follower_id, :followed_id], unique: true 
    end 

的database.yml

development: 
adapter: postgresql 
encoding: unicode 
database: blog_development 
pool: 5 
username: ****** 
password: 
+0

請添加有關該錯誤的** **完整報告。您嘗試提取的「最小特定部分」不夠具體。 –

+0

@ D-side足夠了嗎?請問我是否需要任何信息.. – Takor

+0

是的,遷移文件似乎也被截斷了。 –

回答

0

刪除foreign_key:從真正的微柱,並添加外鍵,如: -

def change 
    create_table :microposts do |t| 
     t.text :content 
     t.references :user, index: true, foreign_key: true 
     t.timestamps :null => false 
    end 
    add_index :microposts, :created_at 
end 
+0

不幸的是,我有同樣的錯誤@ user3506853 – Takor

+0

@Takot,我已經更新了代碼。請檢查 – user3506853

+0

@ user3506853不幸的是,這是一樣的錯誤。我也嘗試過「rake db:reset」,並且我有一個錯誤:** - enable_extension(「plpgsql」) - > 0.0445s - create_table(「microposts」,{:force =>:cascade}) rake中止!** – Takor