paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
390 stars 67 forks source link

`ForeignKey(null=True)` with no default specified should not be auto filled? #58

Closed mrmachine closed 9 years ago

mrmachine commented 9 years ago

I have a bunch of models with ForeignKey fields that can be null and which have no default value specified. DDF always tries to auto fill these fields when I use G(). I end up having to constantly do G(foo=None, ...) to stop it, or put a redundant ForeignKey('Foo', default=None, null=True) in my model.

DDF should only auto fill fields that are required to pass model validation?

JanoValaska commented 9 years ago

I am not sure if this is what you are looking for, but there is global setting called DDF_FILL_NULLABLE_FIELDS (http://django-dynamic-fixture.readthedocs.org/en/latest/ddf.html#global-settings) and it should control this behaviour. I remember that last time I tried to use it it did not work as I expected, but maybe it does now. Please let me know if it works.

Jano

paulocheque commented 9 years ago

Exactly. Use DDF_FILL_NULLABLE_FIELDS or fill_nullable_fields=False.

mrmachine commented 9 years ago

When DDF_FILL_NULLABLE_FIELDS = False, DDF appears to explicitly set unspecified fields to null even when they have a default configured in the model.

Shouldn't it just not set any value at all for those fields, so Django can use its configured default (which is None if there is no default)?

mrmachine commented 9 years ago

Or perhaps a DDF_FILL_DEFAULT_FIELDS setting (True by default for backwards compatibility) that allows the model field default to be used for fields that are not explicitly provided by the user, regardless of the DDF_FILL_NULLABLE_FIELDS setting.

A DDF_FILL_UNIQUE_FIELDS setting might also be useful.