簡體   English   中英

heroku運行rake db:migrate錯誤

[英]heroku run rake db:migrate error

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

看起來是這樣的:

  • 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遷移,以無損地更改數據庫。

參考文獻

看來您已經有了device_create_users試圖重新創建的表用戶(可能來自create_users遷移)

您可以修改create_device_users遷移以僅添加所需的字段

另外,如果它是一個沒有用戶的全新應用程序,則可以放下並嘗試重新運行所有遷移

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM