Heroku的运行耙分贝:迁移错误(heroku run rake db:migrate error

2019-07-29 22:27发布

我希望做我的应用程序,我在Heroku上运行迁移,但我得到这个错误:

Running `rake db:migrate` attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
Migrating to CreateUsers (20120525005302)
Migrating to DeviseCreateUsers (20120611000411)
==  DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  relation "users" already exists
: CREATE TABLE "users" ("id" serial primary key, "email" character varying(255) DEFAULT '' NOT NULL, "encrypted_password" character varying(255) DEFAULT '' NOT NULL, "reset_password_token" character varying(255), "reset_password_sent_at" timestamp, "remember_created_at" timestamp, "sign_in_count" integer DEFAULT 0, "current_sign_in_at" timestamp, "last_sign_in_at" timestamp, "current_sign_in_ip" character varying(255), "last_sign_in_ip" character varying(255), "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 

Tasks: TOP => db:migrate

我在我的github仓库以下迁移文件

  1. 20120525005302_create_users.rb(里面是空的,不知道如何删除它)
  2. 20120611000411_devise_create_users.rb
  3. 20120613140535_create_authentications.rb

Answer 1:

它看起来像以下情况:

  • 20120525005302_create_users.rb将尝试创建一个users在数据库中的表。
  • 20120611000411_devise_create_users.rb也将尝试创建一个users数据库表。
  • 你的数据库目前已经有一个users在其表,所以在第二个迁移,迁移失败。

为了让users表在数据库中正确对应20120611000411_devise_create_users.rb迁移,你可以做两件事情之一:

  1. 回滚(或下降)的数据库,然后再次运行迁移。 (您可以删除20120525005302_create_users.rb如果它是空的。)
  2. 修改您的20120611000411_devise_create_users.rb迁移将降大任现有users做其他事情之前表。
  3. 修改您的20120611000411_devise_create_users.rb迁移如下:
    • 而不是创建的users表,修改现有的表。
    • 添加和修改数据库组件对应

一般来说,如果你的应用程序处于“婴儿状态”,然后重新创建数据库往往是构建应用程序的初始结构的快捷方式。 不过,如果你已经在你的重要数据users表,你会希望保留并通过修改进行20120611000411_devise_create_users.rb迁移更改数据库的非破坏性。

参考

  • 在Heroku上运行rake命令
  • RailsGuides:迁移


Answer 2:

看起来你已经有表的用户(可能是从create_users迁移)是device_create_users正试图重建

您可以通过修改create_device_users迁移只需添加你需要的字段

或者,如果它没有用户带来全新的应用程序,你可以刚落,并尝试重新运行所有的migraions



文章来源: heroku run rake db:migrate error