I have created a migration in which i mistakenly duplicate the columns of "created_at" , now my screen is displaying this error, after when i remove the duplication, the errror was also same before removing the duplication.
This is the terminal messages:
PS C:\Users\iamvee_k\Desktop\Rails Projects\blog> rails db:migrate
== 20231003192318 AddTimestampsToArticles: migrating ==========================
-- add_column(:articles, :created_at, :datetime)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: created_at
C:/Users/iamvee_k/Desktop/Rails Projects/blog/db/migrate/20231003192318_add_timestamps_to_articles.rb:3:in `change'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: created_at
C:/Users/iamvee_k/Desktop/Rails Projects/blog/db/migrate/20231003192318_add_timestamps_to_articles.rb:3:in `change'
Caused by:
SQLite3::SQLException: duplicate column name: created_at
C:/Users/iamvee_k/Desktop/Rails Projects/blog/db/migrate/20231003192318_add_timestamps_to_articles.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

If you are using
create_table, e.g.t.timestampswill create thecreated_atandupdated_atfields for you, so leave it there but remove the extracreated_atyou added manually.When you do, you have two choices:
If you don't care about losing the data you have you can use
rails db:reset. This will drop the databases and run the migrations again (so make sure to fix the issue of having an extracreated_ atbefore running the command)If you don't want to lose the data you can use
rails db:rollback. It will rollback the last migration and you can pass how many steps you want (in your case is 1, but you don't need to pass it) withSTEP. After that just runrails db:migrateagain.For example:
More infos here: https://guides.rubyonrails.org/active_record_migrations.html#rolling-back