update: I did $heroku run rake db:schema:load and I'm not seeing the error in the trace anymore, but I'm still unable to get the application running
I'm uploading my local app to Heroku. After setting up pg within my gemfile for production, I'm facing several issues. My log is returning a PG::DuplicateTable: ERROR: relation "comments" already exists, so I dropped the table by doing rails db and deleting the table named 'comments', as I was following the advice from someone here in Stackoverflow. The thing is that after git push heroku master and run rake db:migrate, I'm still experiencing the same error message.
full trace
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateTable: ERROR: relation "comments" already exists
: CREATE TABLE "comments" ("id" serial primary key, "user_id" integer, "holder_id" integer, "commentable_id" integer, "commentable_type" character varying(255), "commentable_url" character varying(255), "commentable_title" character varying(255), "commentable_state" character varying(255), "anchor" character varying(255), "title" character varying(255), "contacts" character varying(255), "raw_content" text, "content" text, "view_token" character varying(255), "state" character varying(255) DEFAULT 'draft', "ip" character varying(255) DEFAULT 'undefined', "referer" character varying(255) DEFAULT 'undefined', "user_agent" character varying(255) DEFAULT 'undefined', "tolerance_time" integer, "spam" boolean DEFAULT 'f', "parent_id" integer, "lft" integer, "rgt" integer, "depth" integer DEFAULT 0, "created_at" timestamp, "updated_at" timestamp) /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:649:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:641:in `method_missing'
/app/db/migrate/20140619200026_the_comments_create_comments.the_comments_engine.rb:4:in `change'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:595:in `exec_migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:578:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:577:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:953:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 leve
schema.rb
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140626173923) do
create_table "hacks", force: true do |t|
t.text "description"
t.string "image"
t.string "url"
t.datetime "created_at"
t.datetime "updated_at"
t.string "picture"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.integer "draft_comments_count", default: 0
t.integer "published_comments_count", default: 0
t.integer "deleted_comments_count", default: 0
t.integer "user_id"
end
add_index "hacks", ["user_id"], name: "index_hacks_on_user_id"
create_table "identities", force: true do |t|
t.integer "user_id"
t.string "provider"
t.string "uid"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "identities", ["user_id"], name: "index_identities_on_user_id"
create_table "taggings", force: true do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type"
t.integer "tagger_id"
t.string "tagger_type"
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
create_table "tags", force: true do |t|
t.string "name"
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "my_draft_comments_count", default: 0
t.integer "my_published_comments_count", default: 0
t.integer "my_comments_count", default: 0
t.integer "draft_comcoms_count", default: 0
t.integer "published_comcoms_count", default: 0
t.integer "deleted_comcoms_count", default: 0
t.integer "spam_comcoms_count", default: 0
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
create_table "votes", force: true do |t|
t.integer "votable_id"
t.string "votable_type"
t.integer "voter_id"
t.string "voter_type"
t.boolean "vote_flag"
t.string "vote_scope"
t.integer "vote_weight"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope"
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope"
end
the local app is also returning the issue that is unable to find the 'comments' table.
Related
When i try to run heroku run rails db:migrate, i get the following error
Running rails db:migrate on ⬢ sharley... up, run.6479 (Free)
I, [2021-01-03T23:13:45.240708 #4] INFO -- : Migrating to AddTimestampToBlogs (20201225171213)
== 20201225171213 AddTimestampToBlogs: migrating ==============================
-- add_timestamps(:blogs, {:null=>true})
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateColumn: ERROR: column "created_at" of relation "blogs" already exists
/app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `exec'
/app/bin/rails:4:in `<main>'
Caused by:
PG::DuplicateColumn: ERROR: column "created_at" of relation "blogs" already exists
/app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `exec'
/app/bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
This is my schema file
Please, any help will be appreciated. Ive searched all over but to no avail.
ActiveRecord::Schema.define(version: 2020_12_29_225613) do
create_table "blogs", force: :cascade do |t|
t.string "name"
t.string "title"
t.string "content"
t.datetime "created_at", precenter code hereision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "user_id"
t.index ["user_id"], name: "index_blogs_on_user_id"
end
create_table "comments", force: :cascade do |t|
t.string "name"
t.text "body"
t.integer "blog_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "post_id"
t.integer "user_id"
t.index ["blog_id"], name: "index_comments_on_blog_id"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "name"
t.integer "user_id"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "comments", "blogs"
end
This is my add timestamps to blog file
class AddTimestampsToBlogs < ActiveRecord::Migration[6.1]
def change
add_timestamps :blogs, null: true
# backfill existing record with created_at and updated_at
# values making clear that the records are faked
long_ago = DateTime.new(2020, 12, 29)
Blog.update_all(created_at: long_ago, updated_at: long_ago)
# change not null constraints
change_column_null :blogs, :created_at, false
change_column_null :blogs, :updated_at, false
end
end
Is there anything else needed?
You could add add_timestamps(:blogs, {:null=>true}) unless column_exists?(:blogs, :created_at) && column_exists?(:blogs, :updated_at). It looks like someone deployed a migration to fix that before or something and now you're trying as well. With the conditional, it will only run the add_timestamps migration method if there are no created or updated at columns
UPDATE
In the migration add the conditional. With the conditional, it will only run that step if the timestamp columns don't exist. The issue is that you or someone on your team has run the migration on heroku before then possibly rolled back locally and then redployed. The db still has that change, hence the error you're receiving. So if you add the conditional, it will add the time stamp columns only if they already don't exist on that table
def change
add_timestamps :blogs, null: true unless column_exists??(:blogs, :created_at) && column_exists?(:blogs, :updated_at)
# backfill existing record with created_at and updated_at
# values making clear that the records are faked
long_ago = DateTime.new(2020, 12, 29)
Blog.update_all(created_at: long_ago, updated_at: long_ago)
# change not null constraints
change_column_null :blogs, :created_at, false
change_column_null :blogs, :updated_at, false
end
I'm trying to deploy to Heroku and I was getting the sqlite3 error so I followed the instructions on https://devcenter.heroku.com/articles/sqlite3
to switch to postgres but now I'm getting an error when I run rails db:migrate.
I've already tried dropping the database and creating it again with rails db:drop db:create, but haven't been able to get it to work.
My migration:
class CreateRooms < ActiveRecord::Migration[5.2]
def change
create_table :rooms do |t|
t.string :name
t.text :description
t.integer :session_id
t.references :channel, foreign_key: true
t.timestamps
end
end
end
In my room model:
class Room < ApplicationRecord
belongs_to :channel
has_many :users
end
In my Channel model:
class Channel < ApplicationRecord
has_many :rooms, dependent: :destroy
has_many :registrations, dependent: :destroy
has_many :users, through: :registrations
end
I get this error when running rails db:migrate
PG::UndefinedTable: ERROR: relation "channels" does not exist
: CREATE TABLE "rooms" ("id" bigserial primary key, "name" character varying, "description" text, "session_id" integer, "channel_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_1f9c11d4ad"
FOREIGN KEY ("channel_id")
REFERENCES "channels" ("id")
)
/CIS-196/final-project/db/migrate/20201128050333_create_rooms.rb:3:in `change'
bin/rails:4:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "channels" does not exist
: CREATE TABLE "rooms" ("id" bigserial primary key, "name" character varying, "description" text, "session_id" integer, "channel_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_1f9c11d4ad"
FOREIGN KEY ("channel_id")
REFERENCES "channels" ("id")
)
/CIS-196/final-project/db/migrate/20201128050333_create_rooms.rb:3:in `change'
bin/rails:4:in `<main>'
Caused by:
PG::UndefinedTable: ERROR: relation "channels" does not exist
/CIS-196/final-project/db/migrate/20201128050333_create_rooms.rb:3:in `change'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
This is the schema:
ActiveRecord::Schema.define(version: 2020_12_12_224511) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.integer "record_id", null: false
t.integer "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
create_table "channels", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "registrations", force: :cascade do |t|
t.integer "channel_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["channel_id"], name: "index_registrations_on_channel_id"
t.index ["user_id"], name: "index_registrations_on_user_id"
end
create_table "rooms", force: :cascade do |t|
t.string "name"
t.text "description"
t.integer "channel_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "session_id"
t.index ["channel_id"], name: "index_rooms_on_channel_id"
end
create_table "users", force: :cascade do |t|
t.string "username"
t.string "name"
t.string "email", default: "", null: false
t.string "password_hash"
t.text "bio"
t.integer "room_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.index ["room_id"], name: "index_users_on_room_id"
end
end
These are the migration files:
screenshot of migration files
Your rooms table references the channel table. Therefore you need to create the channel table before you create the rooms table. You need to rename the migration which creates the channels table so that it appears before the migration that creates the rooms table.
Thus rename 20201128050352_create_channels.rb to 20201128050332_create_channels.rb so it will run before 20201128050333_create_rooms.rb. Then run rails db:drop db:create db:migrate.
When I try to load my rails app on my localhost I get an error telling me to resolve it by running rails db:migrate but when I try to run the command this is what I get
C:\Sites\CoolGuyGear>rails db:migrate
== 20180108004216 AddDeviseToViews: migrating =================================
-- change_table(:views)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: email: ALTER TABLE "views" ADD "email" varchar DEFAULT '' NOT NULL
C:/Sites/CoolGuyGear/db/migrate/20180108004216_add_devise_to_views.rb:7:in `block in up'
C:/Sites/CoolGuyGear/db/migrate/20180108004216_add_devise_to_views.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: email: ALTER TABLE "views" ADD "email" varchar DEFAULT '' NOT NULL
C:/Sites/CoolGuyGear/db/migrate/20180108004216_add_devise_to_views.rb:7:in `block in up'
C:/Sites/CoolGuyGear/db/migrate/20180108004216_add_devise_to_views.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
SQLite3::SQLException: duplicate column name: email
C:/Sites/CoolGuyGear/db/migrate/20180108004216_add_devise_to_views.rb:7:in `block in up'
C:/Sites/CoolGuyGear/db/migrate/20180108004216_add_devise_to_views.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Migration:
# frozen_string_literal: true
class AddDeviseToViews < ActiveRecord::Migration[5.1]
def self.up
change_table :views 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.string :current_sign_in_ip
t.string :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 :views, :email, unique: true
add_index :views, :reset_password_token, unique: true
# add_index :views, :confirmation_token, unique: true
# add_index :views, :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
create_table "views", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_views_on_email", unique: true
t.index ["reset_password_token"], name:
"index_views_on_reset_password_token", unique: true
end
The answer is in the question.
Whatever migrations you have added are creating duplicate columns in your database as seen in the log generated from the migration.
duplicate column name: email: ALTER TABLE "views" ADD "email"
Create a migration that either removes those columns from your database or go directly into your local mysql/sqlite database and remove those columns manually. Run the migration again and, since you don't already have those columns in your database table, you will not receive these errors.
I'm writing a demo to practice the gem of "carrierwave", and it worked all well in development ENV, but failed when I deployed to Heroku.
When I : heroku run rails s, get this error:
/app/app/models/article.rb:9:in `': uninitialized constant Article::PictureUploader (NameError)
There's my codes:
app/models/article.rb
class Article < ActiveRecord::Base
belongs_to :user
has_many :comments, dependent: :destroy
has_many :likes
validates :title, presence: true, length: {maximum: 50}
validates :content, length: {minimum: 10}
self.per_page = 10
attr_accessor :floor_number
mount_uploader :picture, PictureUploader
validate :picture_size
uploaders/picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_limit: [600, 600]
storage :qiniu
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w{jpg gif png jpeg}
end
end
db/schema.rb
ActiveRecord::Schema.define(version: 20150529021048) do
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "content"
t.string "label"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "picture"
end
add_index "articles", ["user_id"], name: "index_articles_on_user_id"
create_table "comments", force: :cascade do |t|
t.text "content"
t.integer "article_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
add_index "comments", ["article_id"], name: "index_comments_on_article_id"
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
create_table "likes", force: :cascade do |t|
t.integer "likes_num"
t.integer "article_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "likes", ["article_id"], name: "index_likes_on_article_id"
create_table "messages", force: :cascade do |t|
t.text "content"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "messages", ["user_id"], name: "index_messages_on_user_id"
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "name"
t.boolean "admin"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Error:
yesijiedeMacBook-Pro:blog killernova$ heroku run rails c
Running rails c attached to terminal... up, run.2077
/app/app/models/article.rb:9:in <class:Article>': uninitialized constant Article::PictureUploader (NameError)
from /app/app/models/article.rb:1:in'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:472:in block (2 levels) in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:471:ineach'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:471:in block in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:469:ineach'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:469:in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:346:ineager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:inblock in '
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in instance_exec'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:inrun'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:in block in run_initializers'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:inblock in tsort_each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in block (2 levels) in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:ineach_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in block in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:ineach'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:intsort_each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:54:in run_initializers'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application.rb:352:ininitialize!'
from /app/config/environment.rb:5:in <top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application.rb:328:inrequire_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:142:in require_application_and_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:67:inconsole'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in run_command!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in'
from /app/bin/rails:4:in require'
from /app/bin/rails:4:in'
yesijiedeMacBook-Pro:blog killernova$
:qiqiu is another gem "carrierwave-qiniu".
Everything is ok in localhost:3000, so anyone would like to tell me where am I wrong? Thanks!
github: https://github.com/killernova/blog
Have you commit your app/uploaders/ to heroku master?
I have same error, was forget to add those uploader files to remote repository
Very odd problem
I am trying to migrate my database but I keep getting:
PG::UndefinedTable: ERROR: relation "users" does not exist
Here is my migration:
class AddRoleToUser < ActiveRecord::Migration
def up
add_column :users, :role_id, :integer
end
def down
remove_column :users, :role_id
end
end
And my schema:
ActiveRecord::Schema.define(version: 20140205191602) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "horseraces", force: true do |t|
t.integer "horse_id"
t.integer "race_id"
t.datetime "entered"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "horses", force: true do |t|
t.string "name"
t.string "gender"
t.date "DOB"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "races", force: true do |t|
t.string "name"
t.integer "race_number"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", force: true do |t|
t.string "first_name"
t.string "last_name"
t.string "user_name"
t.string "address"
t.string "phone_number"
t.string "email", default: ""
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "role_id"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
I have been trying:
rake db:reset
and
rake db:drop
rake db:create
rake db:migrate
And I get met with the same errors each time.
Interesting that this was working, meaning I had run these commands and got it working. I simply tried to just start fresh and now it's throwing these errors.
Worth noting - I did change a model file from users.rb to user.rb & roles.rb to role.rb I don't know if this would effect anything.
Any help would be much appreciated.
You should load the schema first then migrate:
rake db:schema:load
rale db:migrate
The first command will run your schema.rb file and create the users table. The 2nd will then run your migration and it shouldn't fail because now the users table exists.
This sort of thing often happens when you go back and edit your migrations... might not be exactly what went wrong for you - but it's the first thing that I'd suspect. My strongest suspicion would be that you somehow deleted your "create_users" migration.