You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But I create those suggested migrations and run them, the first one fails with the error:
== 20190314162335 AddIsAdminToUsers: migrating - Shard: master ================
-- add_column(:users, :is_admin, :boolean, {:null=>false})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::NotNullViolation: ERROR: column "is_admin" contains null values
: ALTER TABLE "users" ADD "is_admin" boolean NOT NULL
This is because of null: false in the suggested line
add_column:users,:is_admin,:boolean,null: false
Should instead this line be the following instead?
add_column:users,:is_admin,:boolean,null: true
and an additional third migration should be suggested to set the NOT NULL constraint?
change_column_null:users,:is_admin,false
The text was updated successfully, but these errors were encountered:
Florent2
changed the title
When adding a column with a non-null default the suggestion migration does not work
When adding a column with a non-null default the suggested migration does not work
Mar 14, 2019
Hey @Florent2, thanks for reporting 👍 Yeah, the null option should be removed from the first migration if it's false (since true is the default) and a third migration would be needed to change the null value. Feel free to submit a PR, or I'll get around to it when I have some time.
PostgreSQL version 9.5.13, Ruby 2.3.8 and Rails 4.2.11.
When running this migration
I get this from strong_migrations:
But I create those suggested migrations and run them, the first one fails with the error:
This is because of
null: false
in the suggested lineShould instead this line be the following instead?
and an additional third migration should be suggested to set the
NOT NULL
constraint?The text was updated successfully, but these errors were encountered: