0

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

2 回答 2

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

参考

于 2012-06-13T21:57:42.920 回答
1

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

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

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

于 2012-06-13T21:42:47.603 回答