schema.rb file is empty after I run rails db:migrate

Viewed 37

the summary of the problem: I'm trying to create a simple crud project to practice and when I create a table using rails g migration create_articles it creates a migration file. So when I add the code

`create_table :articles do |t|
 t.string :title
 t.text :description
 t.timestamps
end`

then run the rails command rails db:migrate a schema file is created, but it is completely empty.

ActiveRecord::Schema[7.0].define(version: 2022_08_21_180236) do
  create_table "articles", force: :cascade do |t|
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

end

I have

  • deleted and re-downloaded everything multiple times using a script found on rubyonmac.com
  • I've tried dropping the empty table by generating another migration file and when that gets pushed to the db nothing happens and the table remains
  • use rails db:rollback and that works but when I rerun the migration file the problem persists

like I said in the beginning of the post I'm using a script I found to setup my MacBook Pro easily so I'm not sure where this problem is coming from. thanks in advance for any help.

edit: also the problem persists across new projects created with command rails new blog or using rails g scaffold Articles to create the migrate files then migrate.

1 Answers
bin/rails generate model Article title:string body:text

this code worked for me. I found if I add the columns when generating the migration file in the terminal the file migrates perfectly and the two columns are created. however if I generate a migration file and then go into the file itself in VSCode to make changes before running rails db:migrate it sometimes worked but mostly didn't.

Related