1

Pulled down some updates from Github and ran the migrations rails db:migrate and noticed Git tracking changes to the repo. A shortened diff of schema.rb shows it inserting id: :serial, everywhere?

Anyone know what's going on? Safe to dump this? It's not present on other developer's machines? Is this a setting I'm not aware of?

-  create_table "boxes", force: :cascade do |t|
+  create_table "boxes", id: :serial, force: :cascade do |t|
     t.text "name", default: "", null: false
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
@@ -107,7 +107,7 @@ ActiveRecord::Schema.define(version: 2019_05_27_143936) do
     t.index ["user_id"], name: "index_boxes_on_user_id"
   end

-  create_table "comments", force: :cascade do |t|
+  create_table "comments", id: :serial, force: :cascade do |t|
     t.text "body", null: false
     t.integer "commentable_id", null: false
     t.string "commentable_type", null: false
@@ -116,7 +116,7 @@ ActiveRecord::Schema.define(version: 2019_05_27_143936) do
     t.datetime "updated_at", null: false
   end
Meltemi
  • 37,979
  • 50
  • 195
  • 293

1 Answers1

1

Changes in the generated schema.rb or structure.sql are often caused when you update your postgres server or you update rails.

To this specific problem, it seems there's already an answer: What determines if rails includes id: :serial in a table definition?

siegy22
  • 4,295
  • 3
  • 25
  • 43
  • the answer which you gave as a link just give why it is happening but how to resolve it? – Vishal Sep 24 '20 at 15:06
  • Usually you don't have to solve anything. Just use the newly generated schema or structure. – siegy22 Sep 24 '20 at 15:28
  • but the newly generated schema forced to fail the test cases and shout "ERROR: null value in column "id" violates not-null constraint" – Vishal Sep 24 '20 at 15:33
  • the project started in rails v5.0 and the current version is 5.2, so every new migration alters the old table and changes the type and constraints of the "id" column in the schema.rb – Vishal Sep 24 '20 at 15:35
  • Maybe ask a question on stack overflow with the stacktrace and the expected behaviour :) – siegy22 Sep 24 '20 at 15:51