3YOURMIND / django-add-default-value

This django Migration Operation can be used to transfer a Fields default value to the database scheme.
Apache License 2.0
138 stars 19 forks source link

Support Raw Default Strings #27

Open jpulec opened 3 years ago

jpulec commented 3 years ago

I've run into a couple scenarios where allowing the use of a raw string to be used as a default would be useful. For example to call an unsupported function, like generate_uuid_v4() or to specify a default for a specific type, i.e. '{}'::jsonb as a default for a JSONB column.

Would it make sense to support passing a 'raw' string that wouldn't be escaped when generating the default expression?

David-Wobrock commented 3 years ago

Hi @jpulec, Interesting suggestion, I like it. It would definitely be useful to have this kind of support somehow.

For the '{}'::jsonb case, a cool solution would be to introspect the models, and determine how to interpret AddDefaultValue.value depending on the Field class that is used for the targeted field :)