问题描述
所有的表由Rails应用程序创建的数据库似乎有created_at和updated_at字段。是什么造成这些?难道他们可选的,或者确实对他们一些内部的依赖?
All the tables in the database created by a rails application seem to have created_at and updated_at columns. What creates these? Are they optional, or does something internal rely on them?
推荐答案
他们在默认情况下,当你运行一个模型ActiveRecord的迁移创建。 ActiveRecord的自动填充/更新他们时,你分别创建或更新模型实例(因此底层数据库表行)。
They are created by default when you run the ActiveRecord migration for a model. ActiveRecord automatically populates/updates them when you create or update a model instance (and thus the underlying database table row) respectively.
您可以从模型迁移文件中删除 t.timestamps
行中删除列。
You can remove the columns by removing the t.timestamps
line from within the model migration file.
这篇关于哪里的created_at和updated_at字段从何而来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!