【问题标题】:pg::error error relations users already existspg::error 错误关系用户已经存在
【发布时间】:2018-06-29 22:28:32
【问题描述】:

我正在尝试将我的应用程序部署到 heroku。一切正常,直到我尝试运行“heroku run rake db:migrate”。然后我收到以下错误(请在新选项卡中打开此图像以更好地查看:

我在本地运行了 rake db:drop、rake db:create 和 rake db:migrate。然后我把它推到heroku并尝试再次运行“heroku run rake db:migrate”,但同样的错误。我知道这与已经有用户表的架构有关,但我没有在我的文件中看到它。

宝石文件:

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

我还有其他事情要做还是我错过了什么?

【问题讨论】:

    标签: ruby-on-rails heroku


    【解决方案1】:

    这意味着您的表“用户”已经存在于 heroku 上。您真的要删除 heroku 上的所有表吗?如果是这样,你有你可以做的

    heroku pg:reset DATABASE
    

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

    如果您只想对表进行一些更改,您应该真正使用迁移,例如

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

    PS:在本地删除、创建、迁移数据库不会对 Heroku 上的数据库产生任何影响。

    【讨论】:

    • 感谢您的回答!那么运行“heroku pg:reset DATABASE”后我该怎么办?当我运行“heroku run rake db:migrate”时,它仍然给我错误
    • 您应该在 db/migrate/... 下检查是否有多个“create_table :users”迁移。如果是这样,您必须决定要使用哪个并删除另一个
    • 我喜欢这个对所有 rake 和数据库的回答:stackoverflow.com/questions/10301794/…
    猜你喜欢
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多