【发布时间】:2017-03-08 01:06:20
【问题描述】:
我正在使用 Rails 构建一个新闻应用程序。当我运行 heroku run rake db:migrate 时,我在 heroku 中的表没有更新。我已经尝试了几次heroku重启。我的本地版本中显示了两个项目,但是当我检查 heroku 版本时,这两列始终丢失。我觉得我已经阅读了有关该主题的一百万个堆栈溢出页面,但没有任何效果。
这就是我提交更改的方式:
- git 添加。
- git commit -m "我的更改"
- git push heroku master
- heroku 运行 rake db:migrate
当我尝试添加新帖子时,我在 heroku 日志中收到此错误:
2016-10-25T20:23:05.717260+00:00 app[web.1]: I, [2016-10-25T20:23:05.717163 #3] INFO -- : [5f60f5aa-8453-4a3a-88f3-daf7b5c673d7] Completed 500 Internal Server Error in 37ms (ActiveRecord: 18.7ms)
2016-10-25T20:23:05.718597+00:00 app[web.1]: F, [2016-10-25T20:23:05.718551 #3] FATAL -- : [5f60f5aa-8453-4a3a-88f3-daf7b5c673d7] NoMethodError (undefined method `slug' for #<Post:0x007fb471ff2cd8>):
2016-10-25T20:23:05.718481+00:00 app[web.1]: F, [2016-10-25T20:23:05.718425 #3] FATAL -- : [5f60f5aa-8453-4a3a-88f3-daf7b5c673d7]
2016-10-25T20:23:05.718644+00:00 app[web.1]: F, [2016-10-25T20:23:05.718604 #3] FATAL -- : [5f60f5aa-8453-4a3a-88f3-daf7b5c673d7]
2016-10-25T20:23:05.718727+00:00 app[web.1]: F, [2016-10-25T20:23:05.718688 #3] FATAL -- : [5f60f5aa-8453-4a3a-88f3-daf7b5c673d7] app/controllers/posts_controller.rb:30:in `create'
2016-10-25T20:23:05.718686+00:00 app[web.1]: F, [2016-10-25T20:23:05.718647 #3] FATAL -- : [5f60f5aa-8453-4a3a-88f3-daf7b5c673d7] app/controllers/posts_controller.rb:31:in `block in create'
这是我在本地“帖子”表中的内容:
Post(id: integer, created_at: datetime, updated_at: datetime, title: string, content: string, description: string, User_Id: integer, slug: string, photo_file_name: string, photo_content_type: string, photo_file_size: integer, photo_updated_at: datetime, ranking: string)
这就是我在 Heroku 中所拥有的:
Post(id: integer, created_at: datetime, updated_at: datetime, title: string, content: string, description: string, user_id: integer)
有人可以帮忙吗?你会是我的英雄。这停止了我的一整天。谢谢!
值得一提的是,我之前创建了这个应用程序,然后又删除了它。这是我第二次以相同的名称将相同的应用程序部署到 heroku。我不确定这是否相关。
【问题讨论】:
-
迁移是否列在 schema_migrations 表中?
-
是的。非常非常混乱。
-
如果你删除它,当你运行迁移任务时应该执行迁移。
-
您是否使用 heroku run rake db:migrate:status 检查迁移是否成功运行????
-
所以我运行了 heroku run rake db:migrate:status 并得到了这个。状态迁移 ID 迁移名称 --------------------------------------------------------- -----上升201610192244903添加内容向下邮寄到20161020161113添加描述到发布到发布2016102016013/2113添加slug to post down 20161020202402将附件照片添加到帖子下降20161024210723删除级别从帖子向下 20161024220148 为帖子添加排名
标签: ruby-on-rails ruby git heroku