【问题标题】:Time stamp won't show in my contacts database时间戳不会显示在我的联系人数据库中
【发布时间】:2019-10-06 15:52:11
【问题描述】:

我正在做一个在线课程,我正在尝试设计一个带有用户数据库的网站。我已经建立了一个带有表单/表格的“联系我们”页面。 我无法在 Rails 控制台中显示时间戳 $ Contact.all

这是我的 Schema.rb :

ActiveRecord::Schema.define(version: 20190518115940) do

  create_table "contacts", force: :cascade do |t|
    t.string "name"
    t.string "email"
    t.text   "comments"
  end
end

这是 crate_contacts.rb 文件:

class CreateContacts < ActiveRecord::Migration[5.0]
  def change
    create_table :contacts do |t|
      t.string :name
      t.string :email
      t.text :comments

      t.timestamps
    end
  end
end

【问题讨论】:

    标签: sql ruby-on-rails database timestamp


    【解决方案1】:

    您的schema.rb 对时间戳一无所知。您是否在没有 timestamps 的情况下创建了表,然后将其添加到迁移中?

    如果是这样,您可以使用命令rails db:migrate:redo 重新运行迁移(假设是最后一次),但该表中的所有数据都将被擦除。

    请参阅this guide 了解更多选项。

    【讨论】:

    • 谢谢!我已经更新了我的 schema.rb: ActiveRecord::Schema.define(version: 20190518115940) do create_table "contacts", force: :cascade do |t| t.string "name" t.string "email" t.text "cmets" t.datetime "created_at", null: false t.datetime "updated_at", null: false end end
    • 然后我按照您的建议重新进行了迁移,现在它可以工作了。感谢您的帮助
    • 不客气。请考虑将此答案标记为正确以帮助其他用户。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    相关资源
    最近更新 更多