method to turn on auto_add and auto_add_now fields#111
Open
Jaspreet-singh-1032 wants to merge 1 commit into
Open
method to turn on auto_add and auto_add_now fields#111Jaspreet-singh-1032 wants to merge 1 commit into
Jaspreet-singh-1032 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey guys,
I had a database
modelwhere I hadcreatedandmodifiedDateTimefields withauto_nowandauto_now_add=True. In one of my test case I had useddjango_seedto 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 runseeder.execute()seeder sets theauto_nowandauto_now_addfields ofmodeltoFalseand as a result, I was gettingNOT NULL constraint failed:error inAPIoncreatedandmodifiedfield because seeder had set them asauto_now=Falseandauto_now_add=False.So, I had added a method
turn_on_auto_add_fields(model)which will setauto_nowandauto_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