简体   繁体   中英

Is there any reason to use `default: nil` in a Rails migration for Postgres?

I see default: nil in the migration file of a Rails project I'm working on. In Postgres this results in a NULL value in the db.

Is there any reason why someone would use this?

It seems to me, the same result can be achieved by just skipping setting a default, and the value will be NULL anyway.

I'm asking myself the same question right now. I have two columns on a model that should always be 'nil' to reflect a legacy system decision.

...

I don't think there is a reason to do this, as you say, it defaults to nil. In my case, I've decided to use validates_absence_of :field aswell.

It may not exactly be an answer but someone might find comfort that someone else is doing it like this. I'd be keen to know the disadvantages of implicitly assuming the field will just always stay nil .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM