Rails Heroku 部署
我使用 Heroku 进行部署并且文件传输正常,但该应用程序无法运行。我认为这与生产数据库有关,但我似乎不知道如何解决它。我的应用程序在我的机器上开发时运行良好。我在 Heroku 上运行了一些 rake db 命令,例如
$ heroku rake db:reset --trace
,但
rake 中止了! 没有要加载的文件——faker /app/lib/tasks/sample_data.rake:1:in require' /app/lib/tasks/sample_data.rake:1 /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in
加载' /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in load_tasks' /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in
each' /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in load_tasks' /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:141:in
load_tasks' /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in send' /app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in
method_missing' /应用程序/Rakefile:7 /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in load' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in
raw_load_rakefile' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2017:in load_rakefile' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in load_rakefile' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in
运行' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in
运行' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/bin/rake:31 /usr/ruby1.8.7/bin/rake:19:在“加载”中 /usr/ruby1.8.7/bin/rake:19 (在/app中)
然后,我跑了 $ RAILS_ENV=生产 rake db:migrate --trace
并得到
** 调用 db:migrate (first_time) ** 调用环境(first_time) ** 执行环境 ** 执行 db:migrate == CreateUsers: 迁移 ================================================= ======= -- 创建表(:用户) -> 0.0012秒 == CreateUsers:已迁移(0.0013s)============================================= ==
== AddEmailUniquenessIndex:迁移 ============================================ -- add_index(:users, :email, {:unique=>true}) -> 0.0008秒 == AddEmailUniquenessIndex:已迁移(0.0009s)===================================
== AddPasswordToUsers:正在迁移===== ========================================= -- add_column(:用户、:加密密码、:字符串) -> 0.0352秒 == AddPasswordToUsers:已迁移(0.0353s)========================================
== AddSaltToUsers:正在迁移=================================================== -- add_column(:用户、:盐、:字符串) -> 0.0005秒 == AddSaltToUsers:已迁移(0.0006s)============================================
= = AddAdminToUsers:正在迁移================================================== == -- add_column(:users, :admin, :boolean, {:default=>false}) -> 0.0092秒 == AddAdminToUsers:已迁移(0.0093s)
=============================================创建微博:迁移 ================================================= -- create_table(:微博) -> 0.0009秒 == CreateMicroposts:已迁移(0.0010s) ==========================================
== CreateRelationships : 迁移中============================================== -- create_table(:关系) -> 0.0009秒 -- add_index(:关系, :follower_id) -> 0.0004秒 -- add_index(:关系, :followed_id) -> 0.0004秒 == CreateRelationships: 已迁移 (0.0019s) =======================================
== CreateCarts: 正在迁移 = =================================================== = -- 创建表(:购物车) -> 0.0014秒 == CreateCarts:已迁移(0.0015s)============================================= ==
== CreateLineItems:迁移 =============================================== ===== -- 创建表(:line_items) -> 0.0010秒 == CreateLineItems:已迁移(0.0010s)
============================================= AddQuantityToLineItem:迁移============================================== -- add_column(:line_items, :quantity, :integer, {:default=>1}) -> 0.0006秒 == AddQuantityToLineItem:已迁移(0.0007s)=====================================
== CoupleItemsInCart:正在迁移=== =========================================== == CoupleItemsInCart:已迁移(0.0134s)========================================
== CreateOrders:正在迁移=================================================== = -- 创建表(:订单) -> 0.0011秒 == CreateOrders:已迁移(0.0012s)============================================= ===
AddOrderIdToLineItem: 迁移 =============================================== -- add_column(:line_items, :order_id, :integer) -> 0.0005秒 == AddOrderIdToLineItem:已迁移(0.0005s)======================================
== AddUsernameToUsers:正在迁移== ============================================= -- add_column(:用户, :用户名, :字符串) -> 0.0005秒 == AddUsernameToUsers:已迁移(0.0006s)========================================
== AddUsernameUniquenessIndex:正在迁移======================================= -- add_index(:users, :用户名, {:unique=>true}) -> 0.0012秒 == AddUsernameUniquenessIndex:已迁移(0.0014s)==============================
== CreateStores:正在迁移======== ============================================= -- 创建表(:商店) -> 0.0010秒 == CreateStores:已迁移(0.0011s)============================================= =
== AddPasswordToStores:迁移 ================================================ -- add_column(:商店, :加密密码, :字符串) -> 0.0007秒 == AddPasswordToStores: 已迁移 (0.0008s) =======================================
== AddUsernameToStores: 正在迁移 = ============================================= -- add_column(:商店, :用户名, :字符串) -> 0.0006秒 == AddUsernameToStores: 已迁移 (0.0007s) =======================================
== AddSaltToStores: 正在迁移 = ================================================= -- add_column(:stores, :salt, :string) -> 0.0009秒 == AddSaltToStores:已迁移(0.0010s)
============================================= AddAdminToStores:迁移 =================================================== -- add_column(:stores, :admin, :boolean, {:default=>false}) -> 0.0008秒 == AddAdminToStores:已迁移(0.0009s) ==========================================
== RemoveNameFromOrders : 迁移中 ============================================= -- 删除列(:订单, :名称) -> 0.0062秒 == RemoveNameFromOrders:已迁移(0.0063s)======================================
== AddFirstNameToOrders:正在迁移== =========================================== -- add_column(:订单, :名字, :字符串) -> 0.0005秒 == AddFirstNameToOrders:已迁移(0.0006s)======================================
== AddLastNameToOrders:正在迁移== =========================================== -- add_column(:订单, :姓氏, :字符串) -> 0.0005秒 == AddLastNameToOrders: 已迁移 (0.0006s) =======================================
== AddAddress1ToOrders: 正在迁移 = ============================================= -- add_column(:订单、:地址1、:文本) -> 0.0006秒 == AddAddress1ToOrders:已迁移(0.0007 秒) =======================================
== AddCardExpiresOnToOrders:正在迁移 = ======================================= -- add_column(:订单, :card_expires_on, :日期) -> 0.0005秒 == AddCardExpiresOnToOrders:已迁移(0.0006s)================================
== AddBillingidToUsers:正在迁移====== ======================================= -- add_column(:用户, :billing_id, :string) -> 0.0005秒 == AddBillingidToUsers:已迁移(0.0006 秒) =======================================
== RemoveNameFromStores:正在迁移 = =========================================== -- 删除列(:商店, :名称) -> 0.0093秒 ==RemoveNameFromStores:已迁移(0.0094s)========================================
RemoveSaltFromStores:正在迁移== =========================================== -- 删除列(:存储,:盐) -> 0.0079秒 ==RemoveSaltFromStores:已迁移(0.0080s)==========================================
RemoveAdminFromStores:正在迁移== ========================================= -- 删除列(:商店,:管理) -> 0.0065秒 ==RemoveAdminFromStores:已迁移(0.0066s)=======================================
RemoveUsernameFromStores:正在迁移=== ===================================== --remove_column(:商店,:用户名) -> 0.0063秒 == RemoveUsernameFromStores:已迁移(0.0065s)==================================
== AddStorenameToStores:正在迁移====== ======================================= -- add_column(:商店, :商店名称, :字符串) -> 0.0006秒 == AddStorenameToStores:已迁移(0.0007s)======================================
== RemoveEncryptedPasswordFromStores:正在迁移== =========================== -- 删除列(:商店,:加密密码) -> 0.0060秒 == RemoveEncryptedPasswordFromStores:已迁移(0.0061 秒) =======================
== AddUserIdToStores:正在迁移 =============== =============================== -- add_column(:stores, :user_id, :integer) 耙子中止! 发生错误,此迁移和所有后续迁移均已取消:
SQLite3::SQLException: 重复的列名称: user_id: ALTER TABLE "stores" ADD "user_id" 整数
错误:
== AddUserIdToStores: 迁移 ========= ======================================= -- add_column(:stores, :user_id, :integer) 耙子中止! 发生错误,此迁移和所有后续迁移均已取消:
SQLite3::SQLException: 重复的列名称: user_id: ALTER TABLE "stores" ADD "user_id" 整数
我没有收到此消息,因为我没有两次添加此列。我搞乱了迁移文件,这与此有什么关系吗?谢谢。我真的希望有人能帮忙解决这个问题。
I deployed with Heroku and files transferred fine, but the app isn't working. I think it has something to do with production database but I can't seem to figure out how to solve it. My app works fine under development on my machine. I ran some rake db commands on heroku such as
$ heroku rake db:reset --trace
and I got
rake aborted!
no such file to load -- faker
/app/lib/tasks/sample_data.rake:1:in require'
load'
/app/lib/tasks/sample_data.rake:1
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in load_tasks'
each'
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/engine.rb:131:in load_tasks'
load_tasks'
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:141:in
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in send'
method_missing'
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in
/app/Rakefile:7
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in load'
raw_load_rakefile'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2017:in load_rakefile'
standard_exception_handling'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in load_rakefile'
run'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling'
run'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/bin/rake:31
/usr/ruby1.8.7/bin/rake:19:in `load'
/usr/ruby1.8.7/bin/rake:19
(in /app)
then, I ran
$ RAILS_ENV=production rake db:migrate --trace
and got
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== CreateUsers: migrating ====================================================
-- create_table(:users)
-> 0.0012s
== CreateUsers: migrated (0.0013s) ===========================================
== AddEmailUniquenessIndex: migrating ========================================
-- add_index(:users, :email, {:unique=>true})
-> 0.0008s
== AddEmailUniquenessIndex: migrated (0.0009s) ===============================
== AddPasswordToUsers: migrating =============================================
-- add_column(:users, :encrypted_password, :string)
-> 0.0352s
== AddPasswordToUsers: migrated (0.0353s) ====================================
== AddSaltToUsers: migrating =================================================
-- add_column(:users, :salt, :string)
-> 0.0005s
== AddSaltToUsers: migrated (0.0006s) ========================================
== AddAdminToUsers: migrating ================================================
-- add_column(:users, :admin, :boolean, {:default=>false})
-> 0.0092s
== AddAdminToUsers: migrated (0.0093s) =======================================
== CreateMicroposts: migrating ===============================================
-- create_table(:microposts)
-> 0.0009s
== CreateMicroposts: migrated (0.0010s) ======================================
== CreateRelationships: migrating ============================================
-- create_table(:relationships)
-> 0.0009s
-- add_index(:relationships, :follower_id)
-> 0.0004s
-- add_index(:relationships, :followed_id)
-> 0.0004s
== CreateRelationships: migrated (0.0019s) ===================================
== CreateCarts: migrating ====================================================
-- create_table(:carts)
-> 0.0014s
== CreateCarts: migrated (0.0015s) ===========================================
== CreateLineItems: migrating ================================================
-- create_table(:line_items)
-> 0.0010s
== CreateLineItems: migrated (0.0010s) =======================================
== AddQuantityToLineItem: migrating ==========================================
-- add_column(:line_items, :quantity, :integer, {:default=>1})
-> 0.0006s
== AddQuantityToLineItem: migrated (0.0007s) =================================
== CombineItemsInCart: migrating =============================================
== CombineItemsInCart: migrated (0.0134s) ====================================
== CreateOrders: migrating ===================================================
-- create_table(:orders)
-> 0.0011s
== CreateOrders: migrated (0.0012s) ==========================================
== AddOrderIdToLineItem: migrating ===========================================
-- add_column(:line_items, :order_id, :integer)
-> 0.0005s
== AddOrderIdToLineItem: migrated (0.0005s) ==================================
== AddUsernameToUsers: migrating =============================================
-- add_column(:users, :username, :string)
-> 0.0005s
== AddUsernameToUsers: migrated (0.0006s) ====================================
== AddUsernameUniquenessIndex: migrating =====================================
-- add_index(:users, :username, {:unique=>true})
-> 0.0012s
== AddUsernameUniquenessIndex: migrated (0.0014s) ============================
== CreateStores: migrating ===================================================
-- create_table(:stores)
-> 0.0010s
== CreateStores: migrated (0.0011s) ==========================================
== AddPasswordToStores: migrating ============================================
-- add_column(:stores, :encrypted_password, :string)
-> 0.0007s
== AddPasswordToStores: migrated (0.0008s) ===================================
== AddUsernameToStores: migrating ============================================
-- add_column(:stores, :username, :string)
-> 0.0006s
== AddUsernameToStores: migrated (0.0007s) ===================================
== AddSaltToStores: migrating ================================================
-- add_column(:stores, :salt, :string)
-> 0.0009s
== AddSaltToStores: migrated (0.0010s) =======================================
== AddAdminToStores: migrating ===============================================
-- add_column(:stores, :admin, :boolean, {:default=>false})
-> 0.0008s
== AddAdminToStores: migrated (0.0009s) ======================================
== RemoveNameFromOrders: migrating ===========================================
-- remove_column(:orders, :name)
-> 0.0062s
== RemoveNameFromOrders: migrated (0.0063s) ==================================
== AddFirstNameToOrders: migrating ===========================================
-- add_column(:orders, :first_name, :string)
-> 0.0005s
== AddFirstNameToOrders: migrated (0.0006s) ==================================
== AddLastNameToOrders: migrating ============================================
-- add_column(:orders, :last_name, :string)
-> 0.0005s
== AddLastNameToOrders: migrated (0.0006s) ===================================
== AddAddress1ToOrders: migrating ============================================
-- add_column(:orders, :address1, :text)
-> 0.0006s
== AddAddress1ToOrders: migrated (0.0007s) ===================================
== AddCardExpiresOnToOrders: migrating =======================================
-- add_column(:orders, :card_expires_on, :date)
-> 0.0005s
== AddCardExpiresOnToOrders: migrated (0.0006s) ==============================
== AddBillingidToUsers: migrating ============================================
-- add_column(:users, :billing_id, :string)
-> 0.0005s
== AddBillingidToUsers: migrated (0.0006s) ===================================
== RemoveNameFromStores: migrating ===========================================
-- remove_column(:stores, :name)
-> 0.0093s
== RemoveNameFromStores: migrated (0.0094s) ==================================
== RemoveSaltFromStores: migrating ===========================================
-- remove_column(:stores, :salt)
-> 0.0079s
== RemoveSaltFromStores: migrated (0.0080s) ==================================
== RemoveAdminFromStores: migrating ==========================================
-- remove_column(:stores, :admin)
-> 0.0065s
== RemoveAdminFromStores: migrated (0.0066s) =================================
== RemoveUsernameFromStores: migrating =======================================
-- remove_column(:stores, :username)
-> 0.0063s
== RemoveUsernameFromStores: migrated (0.0065s) ==============================
== AddStorenameToStores: migrating ===========================================
-- add_column(:stores, :store_name, :string)
-> 0.0006s
== AddStorenameToStores: migrated (0.0007s) ==================================
== RemoveEncryptedPasswordFromStores: migrating ==============================
-- remove_column(:stores, :encrypted_password)
-> 0.0060s
== RemoveEncryptedPasswordFromStores: migrated (0.0061s) =====================
== AddUserIdToStores: migrating ==============================================
-- add_column(:stores, :user_id, :integer)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: user_id: ALTER TABLE "stores" ADD "user_id" integer
The error:
== AddUserIdToStores: migrating ==============================================
-- add_column(:stores, :user_id, :integer)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: user_id: ALTER TABLE "stores" ADD "user_id" integer
I don't get this because I didn't add this column twice. I messed around with migration files, does that have anything to do with this? Thanks. I really hope somebody can help with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您连续运行足够多的迁移时,迁移往往会中断。如果您从头开始创建数据库,请使用:
通常我倾向于在我的开发数据库中获取一些合理的内容,然后简单地使用
如果您不熟悉它,它会将架构和数据从您的开发数据库复制到heroku上的应用程序数据库。其中任何一个都可能是解决您的问题的合理解决方法。
我希望这有帮助。
Migrations tend to break when you run enough of them in a row. If you are creating your db from scratch use:
Generally I tend to get something reasonable going in my dev database and simply use
If you are not familiar with it, it will copy both schema and data from your dev db to your app db on heroku. Either one of those might be a reasonable workaround for your issue.
I hope that helps.