ga-wdi-exercises / project4

[project]
https://github.com/ga-wdi-exercises/project4
2 stars 8 forks source link

devise #306

Closed pamelaolney closed 8 years ago

pamelaolney commented 8 years ago

Hi,

my repo: https://github.com/pamelaolney/makali branch: devise

I am trying to use devise. This is a first for me. I keep getting this error when I try to rake db:migrate

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

PG::UndefinedTable: ERROR:  relation "users" does not exist
: ALTER TABLE "users" ADD "email" character varying DEFAULT '' NOT NULL
/home/pam/Documents/GA/projects/4project/makali/makali/db/migrate/20160913133207_add_devise_to_users.rb:5:in `block in up'
/home/pam/Documents/GA/projects/4project/makali/makali/db/migrate/20160913133207_add_devise_to_users.rb:3:in `up'
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "users" does not exist

Not sure why. I am following the mini lesson instructions.

https://github.com/ga-wdi-lessons/rails_features_CRD

I deleted my previous user information without devise and recreated it. I read this stack overflow response about it and the guy said that it had something to do with duplicate pg table? I am having trouble checking if that is my issue.

http://stackoverflow.com/questions/18306132/rails-app-installing-devise-rake-dbmigrate-error#comment27005675_18322481

User migrations

class CreateUsers < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
    end
  end
end
class AddDeviseToUsers < ActiveRecord::Migration[5.0]
  def self.up
    change_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.inet     :current_sign_in_ip
      t.inet     :last_sign_in_ip

      ## Confirmable
      # t.string   :confirmation_token
      # t.datetime :confirmed_at
      # t.datetime :confirmation_sent_at
      # t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
      # t.string   :unlock_token # Only if unlock strategy is :email or :both
      # t.datetime :locked_at

      # Uncomment below if timestamps were not included in your original model.
      # t.timestamps null: false
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    # add_index :users, :confirmation_token,   unique: true
    # add_index :users, :unlock_token,         unique: true
  end

  def self.down
    # By default, we don't want to make any assumption about how to roll back a migration when your
    # model already existed. Please edit below which fields you would like to remove in this migration.
    raise ActiveRecord::IrreversibleMigration
  end
end

Activities Migrations

class CreateActivities < ActiveRecord::Migration[5.0]
  def change
    create_table :activities do |t|
      t.string :title
      t.references :user

      t.timestamps
    end
  end
end

Not sure if my seed file would be related at all. But I had user id's for each activity previously and a User.destroy and User.create. Now it is no longer there because I thought it would negatively affect things. Should I bring that back?

Seed file

Activity.destroy_all

  beach = Activity.create(
    title: "Go to the beach",
  )
  diy = Activity.create(
    title: "Crotchet 3 scarves and pass them out to the homeless",
  )
  fight = Activity.create(
    title: "Take a boxing course",
  )
  spar = Activity.create(
    title: "Go to a fighting meet-up and spar",
  )
  kpop = Activity.create(
    title: "Try to sneak into Kpop invite only event",
  )
  hair = Activity.create(
    title: "Go to a popular korean salon and ask them to surprise you",
  )
andrewsunglaekim commented 8 years ago

sounds like you have a migration thats happening before the user one thats using users as a foreign key.

pamelaolney commented 8 years ago

Do I need to set foreign key somewhere? I have been working on this for a while. I tried adding user seeds to my seed file. tried removing my migrations and re-adding them. tried to manually input the reference user. Not sure where the problem is :(

pamelaolney commented 8 years ago

forget it

andrewsunglaekim commented 8 years ago

i'm so sorry, didn't realize this got closed!

andrewsunglaekim commented 8 years ago

were you able to figure it out?