Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method to turn on auto_add and auto_add_now fields #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jaspreet-singh-1032
Copy link

@Jaspreet-singh-1032 Jaspreet-singh-1032 commented Jan 23, 2022

Hey guys,
I had a database model where I had created and modified DateTime fields with auto_now and auto_now_add=True. In one of my test case I had used django_seed to generate the objects. And I had another test case where I was testing API with post request to create the object. The issue I was facing was when we run seeder.execute() seeder sets the auto_now and auto_now_add fields of model to False and as a result, I was getting NOT NULL constraint failed: error in API on created and modified field because seeder had set them as auto_now=False and auto_now_add=False.

So, I had added a method turn_on_auto_add_fields(model) which will set auto_now and auto_now_add=True. So, that it should be added automatically through the API call.
I also have added TestCases to raise the error and fix the error after turning on the auto fields.
And a lot of stuff had changed maybe because of auto-formatting. Let me know if I need to make it like it was before :).
Fixes #109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

turn_off_auto_add() caused Model.objects.create() error
1 participant