I have a table, name it MyTable . It is part of the Postgresql database.
MyTable lot of entries, say, over a million. I would like to add a field to this table, name it MyNewField . It must be added using ActiveRecord migration.
This field must be without default values ββand not equal to NULL. As a result, the migration class in it will be something like this:
class AddMyFieldToMyTable < ActiveRecord::Migration def change add_column :my_table, :my_field, :text, null: false end end
However, it will throw an error (PG :: NotNullViolation) because the table already contains rows, all of which will have MyField set to NULL.
I would like to do the following: add a line without a default value and set the NULL value to false (without starting PG :: NotNullViolation). Then paste the value from another table into each record.
This would probably be possible by adding a field with a null value to true, and then adding values, and then changing the value to nullable to false. However, I am interested to know if this can be done in one shot.
source share