gpt4 book ai didi

ruby-on-rails - heroku 运行 rake db :migrate error

转载 作者:行者123 更新时间:2023-11-29 14:23:46 26 4
gpt4 key购买 nike

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

引用资料

关于ruby-on-rails - heroku 运行 rake db :migrate error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11023645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com