1

new to ROR. i'm taking one month rails and :

i cannot get past f'n $ rake db:migrate!!!!

I'm getting this message now

gregs-MacBook-Air:trydah gregfrontiero
$ rake db:migrate

== 20140606025644 AddDeviseToUsers: migrating =================================

-- change_table(:users)

rake aborted!

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

SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL/Users/gregfrontiero/.rvm/gems/ruby-2.1.2/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:ininitialize' "`

I saw something on StackOverflow saying to reset and got this:

gregs-MacBook-Air:trydah gregfrontiero$ rake db:reset

/Users/gregfrontiero/Desktop/trydah/db/schema.rb doesn't exist yet. Runrake db:migrateto create it, then try again. If you do not intend to use a database, you should instead alter /Users/gregfrontiero/Desktop/trydah/config/application.rb to limit the frameworks that will be loaded.

If you let me know how to fix this, i will build several shrines in your honor.

Thanks again,

Greg

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • 1
    `users` does not exist as a table. You need to create it before altering it. – Joe Kennedy Jun 06 '14 at 03:55
  • thanks jken. i'm super new to programming. how would i create a 'users' table? – user3709406 Jun 06 '14 at 03:59
  • 1
    The [Rails Guides](http://guides.rubyonrails.org/) are incredibly helpful when you're just getting started with Rails. To learn how to create and alter tables, check out the [Database Migrations Rails Guide](http://guides.rubyonrails.org/migrations.html). – Joe Kennedy Jun 06 '14 at 04:17

2 Answers2

4

As mentioned in the comments, the error clearly states this:

no such table: users

The problem you have is you're trying to change a table which does not exist. If you have created the table in previous migrations & deleted on your server, you may want to use rake db:reset, however as you've already used that command with errors, you'll probably have to set up a new table.

--

I think you'll be best doing this:

$ rails g migration CreateUserTable

#db/[timestamp]_create_users.rb
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
        #... columns here
        t.timestamps
    end
  end
end

If you then remove the content out of the migration you have currently - allowing you to run this new one, you'll be able to create the database by running rake db:migrate. After that, you need to create a new migration, copy the commented-out one, and paste into the new one.

This will allow you to run the change commands in your database, as the db will be present on the system.

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
0

Maybe try starting with:

rake db:setup

then

rake db:migrate

Also, if you have setup Devise before you've created your database, you may need to comment out the devise_for :users line in your routes.rb.

When your rails environment is loaded during rake it loads routes, which calls this devise_for :users which is looking for your users table, which doesn't yet exist and is the very thing that you're trying to create.

Dave Bryand
  • 601
  • 6
  • 11