0

I am trying to deploy my app to heroku. Everything works fine until I try to run "heroku run rake db:migrate". Then I get the following error (please open this image in new tab to see better: Error

I ran rake db:drop, rake db:create, and rake db:migrate locally. Then I pushed it to heroku and tried running "heroku run rake db:migrate" again, but same error. I know this has something to with the schema already having user table, but I don't see it on my files.

Gem file:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# for users
gem 'devise', '~> 4.2'
# Use ActiveModel has_secure_password
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
# Use Unicorn as the app server
# gem 'unicorn'
gem 'tzinfo-data'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
end

group :test do
  # for seeing test covarage
  gem 'simplecov', :require => false
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'sqlite3'
end
# upload files
gem 'carrierwave', '~> 1.0'

# bootstraps
gem 'bootstrap-sass', '~> 3.3.4.1'
# Material Icons
gem 'material_icons'
# Material css
gem 'materialize-sass'

group :production do
    gem 'pg', '0.15'
    gem 'rails_12factor'
end

Is there something else I have to do or am I missing something?

Jasonbigg
  • 25
  • 6

1 Answers1

0

That means your table "users" already exists on heroku. Do you really want to delete all tables on heroku ? If so, you have you can do

heroku pg:reset DATABASE

https://devcenter.heroku.com/articles/heroku-postgresql#pg-reset

If you only want to make some changes on your tables you should really work with migrations like

add_column :users, :my_attribute, ...
removeColumn :users, :my_attribute_to_remove

PS: To drop, create, migrate the db locally will not have any effects at the db on heroku.

Simon Franzen
  • 2,628
  • 25
  • 34
  • Thanks for your answer! So what should I do after running "heroku pg:reset DATABASE"? It still gives me the error when I run "heroku run rake db:migrate" – Jasonbigg Jan 20 '18 at 23:47
  • You should check under db/migrate/... if there a more than one migration with "create_table :users". If so, you have to decide which you want to use and delete the other – Simon Franzen Jan 21 '18 at 00:44
  • 1
    I love this answer to all things rake and databases: https://stackoverflow.com/questions/10301794/difference-between-rake-dbmigrate-dbreset-and-dbschemaload – codenoob Jan 21 '18 at 03:23