rails column datetime
rails generate migration AddTimestampsToTableName created_at:datetime updated_at:datetime
rails generate migration
: This command generates a new migration file for making changes to the database schema.AddTimestampsToTableName
: The name of the migration file, following the convention of adding timestamps to a specific table. ReplaceTableName
with the actual name of the table you want to modify.created_at:datetime updated_at:datetime
: Specifies two columns,created_at
andupdated_at
, with the data typedatetime
. These columns are automatically managed by Rails to track when a record is created or updated.After running this migration and applying it to the database (
rails db:migrate
), the specified table will havecreated_at
andupdated_at
columns added to it, allowing Rails to automatically update these fields whenever a new record is created or an existing record is updated.