0

I had use sqlite as database for my rails app, then I changed it with Postgresql and after that I started to get an error when I tried to add new migrations.

Error

 $ 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::Migration

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

  t.timestamps null: false
end

_microposts.rb< ActiveRecord::Migration

 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::Migration

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

AddPasswordDigestToUsers< ActiveRecord::Migration

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

AddRememberDigestToUsers< ActiveRecord::Migration

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

AddAdminToUsers< ActiveRecord::Migration

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

AddActivationToUsers< ActiveRecord::Migration

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

CreateRelationships< ActiveRecord::Migration

     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:  
Takor
  • 277
  • 2
  • 12
  • Please, add a **complete** report about the error. The "minimal specific part" you attempted to extract is not specific enough. – D-side Dec 02 '15 at 10:03
  • @D-side Is it enough? Please ask me if you need any information.. – Takor Dec 02 '15 at 10:09
  • Yeah, migration files appear to be truncated too. – D-side Dec 02 '15 at 10:10
  • @D-side I've run "rake:db migrate --trace" and also add all migration files I try to add my database.. – Takor Dec 02 '15 at 10:39
  • Oh. That might be the issue. Every migration is supposed to be wrapped in a class inheriting from `ActiveRecord::Migration`. Did you just edit that out or is it just not there? – D-side Dec 02 '15 at 10:41
  • I've already edited :) Yes they have classes that inheriting from ActiveRecord::Migration @D-side – Takor Dec 02 '15 at 10:45
  • Hm. I'm clueless for now. Here's [a link to a failing line](https://github.com/rails/rails/blob/v4.2.4/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L99), I'll try to reproduce that later. – D-side Dec 02 '15 at 10:48
  • @D-side Thanks for your attention, I'm also looking for why I have this error. If I can find it, I'll back to you too.. – Takor Dec 02 '15 at 10:52

1 Answers1

0

Remove foreign_key: true from micropost and add foreign key like :-

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
user3506853
  • 814
  • 5
  • 3
  • @ user3506853 Unfortunately, It's same error. I also tried " rake db:reset " and I had an error that **-- enable_extension("plpgsql") -> 0.0445s -- create_table("microposts", {:force=>:cascade}) rake aborted!** – Takor Dec 02 '15 at 09:35
  • I added all migration files that I want to add my app. And also I run " rake db:migrate --trace" then I've edit my question. It maybe become useful for you to answer my question. – Takor Dec 02 '15 at 10:41