-1
class AddPlacesTable < ActiveRecord::Migration[7.0]
  def change
    create_table :places, id: :uuid do |t|
      t.string :name, null:false
      t.string :address, null:false
      t.string :city, null:false

      t.timestamps
    end
  end
end

This is my database file and the following is the error it is throwing.

SQLite3::ConstraintException: NOT NULL constraint failed: places.id (ActiveRecord::NotNullViolation)

and my model file is empty it just have a class which is inheriting from ApplicationRecord.

When i start creating a row in my database it shows null for places.id but i think rails should automatically assign it a value since it is a primary key.

dbugger
  • 15,868
  • 9
  • 31
  • 33
s-chuck
  • 23
  • 4
  • Does this answer your question? [Rails 5 uuid issue with sqlite](https://stackoverflow.com/questions/47243229/rails-5-uuid-issue-with-sqlite) – dbugger Jul 21 '23 at 12:28

1 Answers1

0

It is blowing up because you have told rails that id is of type uuid.

Rails does not know how to create the uuid. The normal thing for a rails app is for you NOT to specify the type of the id column. It will be created for you and will be an integer and will be automatically populated. By specifying the uuid type you have told rails not to do the normal default thing so it is letting you do you.

Recreate the table without that and you will be on your way.

kwerle
  • 2,225
  • 22
  • 25