heroku运行rake db:迁移错误
我想在我的应用程序上运行我在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 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 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 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存储库中有以下迁移文件
- 20120525005302_create_users.rb(这是空的,不知道如何删除它)
- 20120611000411_devise_create_users.rb
- 20120613140535_create_authentications.rb
看起来如下:
-
20120525005302_create_users.rb
将尝试在数据库中创建users
表。 -
20120611000411_devise_create_users.rb
还将尝试在数据库中创建users
表。 - 您的数据库当前已有一个
users
表,因此迁移在第二次迁移时失败。
要使数据库中的users
表与20120611000411_devise_create_users.rb
迁移正确对应,您可以执行以下两项操作之一:
- 回滚(或删除)数据库,然后再次运行迁移。 (如果它为空,您可以删除
20120525005302_create_users.rb
。) - 在执行任何其他操作之前,请修改
20120611000411_devise_create_users.rb
迁移以删除任何现有users
表。 - 修改您的
20120611000411_devise_create_users.rb
迁移,如下所示:- 而不是创建
users
表,修改现有表。 - 添加和修改数据库组件以进行对应
- 而不是创建
通常,如果您的应用程序处于“婴儿状态”,则重新创建数据库往往是构建应用程序初始结构的快速方法。 但是,如果您的users
表中已有重要数据,则需要保留该数据,然后通过修改20120611000411_devise_create_users.rb
迁移来非破坏性地更改数据库。
参考
- 在Heroku上运行Rake命令
- RailsGuides:迁移
看起来你已经有了table_create_users尝试重新创建的表用户(可能来自create_users migration)
您可以修改create_device_users迁移,只需添加所需的字段即可
或者,如果它是一个没有用户的全新应用程序,您可以放弃并尝试重新运行所有迁移