rake aborted database will not migrate

5.7k views Asked by At

I created models, views, and controllers for 'startups' each individually (without scaffolding). I have a file db>migrate>'201..._create_startups.rb' with the code below:

class CreateStartups < ActiveRecord::Migration
  def change
    create_table :startups do |t|
        t.string :name
        t.string :location
        t.string :description

      t.timestamps null: false
    end
  end
end

I ran "bundle exec rake db:migrate" and I get this response:

== 20141126011749 CreateStartups: migrating ===================================
-- create_table(:startups)
   -> 0.0155s
== 20141126011749 CreateStartups: migrated (0.0159s) ==========================

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (1 for 0)/Users/kevinmircovich/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'

Once I run my local server and go to my browser to view my app, I have the message below:

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

Extracted source (around line #393):
392 def check_pending!(connection = Base.connection)
393       raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?>.>(connection)
394     end
395
396     def load_schema_if_pending!

I ran "bin/rake db:migrate RAILS_ENV=development" and had the same error as I did when I ran "bundle exec rake db:migrate":

wrong number of arguments (1 for 0)

3

There are 3 answers

2
Roaring Stones On

no need to "null: false" on timestamps: it is not users' input: those are set by the active model itself, so you can remove the argument.

1
Mehul Gurjar On

In Rails migration t.timestamp macro adds two columns, created_at and updated_at. These special columns are automatically managed by Active Record if they exist.

It will automatically update when new recored created & updated.

Please remove null:false argument from t.timestamp.

class CreateStartups < ActiveRecord::Migration
  def change
    create_table :startups do |t|
        t.string :name
        t.string :location
        t.string :description

      t.timestamps 
    end
  end
end
0
Ravi On

I received a similar error when running rake:db migrate. To resolve my issue I ran rake:db drop to drop my database since I was in dev mode with no production database. Then I recreate the database with rake db:create after which i ran rake db:migrate successfully.

Error running rake db:migrate ActiveRecord::PendingMigrationError Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.


Resolved using:

rake db:drop - this will wipe the data out of your database rake db:create rake db:migrate