【问题标题】:heroku run rake db:migrate errorheroku 运行 rake db:迁移错误
【发布时间】:2012-06-16 22:16:37
【问题描述】:

我想在我在 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

【问题讨论】:

    标签: ruby-on-rails postgresql heroku rails-migrations


    【解决方案1】:

    您似乎已经有 device_create_users 正在尝试重新创建的表用户(可能来自 create_users 迁移)

    您可以修改您的 create_device_users 迁移以仅添加您需要的字段

    或者,如果它是一个没有用户的全新应用程序,您可以放弃并尝试重新运行所有迁移

    【讨论】:

    • 我不能只从我的应用程序和 github 上删除该迁移。我该怎么做?
    • git rm 20120525005302_create_users.rb git push origin master heroku run rake db:drop heroku run rake db:create heroku run rake db:migrate
    【解决方案2】:

    看起来以下是真的:

    • 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 迁移以非破坏性地更改数据库。

    参考文献

    【讨论】:

    • 我回滚了所有的迁移,我没有第一次迁移,我把所有东西都推到了 github 上,它仍然在那里..
    • 我现在已经删除了迁移文件,仍然得到同样的错误。
    • 听起来最简单的方法是将更改从新数据库应用到服务器的数据库。此外,如果您更改 20120611000411_devise_create_users.rb 的行为,好的做法是更改其名称以反映该行为(即,20120611000411_devise_modify_users.rb 之类的东西。)
    猜你喜欢
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 2023-03-04
    • 1970-01-01
    • 2015-03-25
    • 2013-02-01
    相关资源
    最近更新 更多