I have this field in my model created_at = models.DateTimeField( auto_now_add = True )
When I try to make migrations I get an error:
You are trying to add the field 'created_at' with 'auto_now_add=True' to user wi
thout a default; the database needs something to populate existing rows.
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
I tried to set the default value but it says default
and auto_now_add
are mutually exclusive. Of course I could just use default without auto_now_add
but I want to know why this error pops up. Did I miss something?
auto_now - updates the value of field to current time and date every time the Model. save() is called. auto_now_add - updates the value with the time and date of creation of record.
auto_now_add Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it's not just a default value that you can override.
Delete the migration file in app and you can makemigrtion process at the time no error raises, It raises due to the reason of previously created time object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With